From e174048d44d12d27fbfce30c50700b4501b8130a Mon Sep 17 00:00:00 2001 From: Augustin AFFOGNON Date: Sat, 22 Oct 2022 18:25:19 +0200 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'Sources/BowlingLib?= =?UTF-8?q?/Model/Joueur.cs'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/BowlingLib/Model/Joueur.cs | 115 +++++++++++++++-------------- 1 file changed, 58 insertions(+), 57 deletions(-) diff --git a/Sources/BowlingLib/Model/Joueur.cs b/Sources/BowlingLib/Model/Joueur.cs index 4413a6e..a34a183 100644 --- a/Sources/BowlingLib/Model/Joueur.cs +++ b/Sources/BowlingLib/Model/Joueur.cs @@ -1,57 +1,58 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BowlingLib.Model -{ - /// - /// Classe Model Joueur - /// - public class Joueur - { - private string pseudo; - private readonly long id; - public long Id - { - get { return id; } - } - - public Joueur(string pseudo) - { - this.Pseudo = pseudo; - } - - public Joueur(long id,string pseudo) : this(pseudo) - { - this.id = id; - } - - public string Pseudo - { - get { return pseudo; } - set - { - - pseudo = value; - if (pseudo == null || pseudo == "" || pseudo.Length < 3) - { - throw new ArgumentException("Le pseudo ne peut pas être vide"); - } - } - } - - public override bool Equals(object obj) - { - return obj is Joueur joueur && - pseudo == joueur.pseudo && - Pseudo == joueur.Pseudo; - } - - public override int GetHashCode() - { - return HashCode.Combine(id, Id, Pseudo); - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BowlingLib.Model +{ + /// + /// Classe Model Joueur + /// + public class Joueur IEquatable + { + private string pseudo; + private readonly long id; + public long Id + { + get { return id; } + } + + public Joueur(string pseudo) + { + this.Pseudo = pseudo; + } + + public Joueur(long id,string pseudo) : this(pseudo) + { + this.id = id; + } + + public string Pseudo + { + get { return pseudo; } + set + { + + pseudo = value; + if (string.IsNullOrWhiteSpace(pseudo) || pseudo.Length < 3) + { + throw new ArgumentException("Le pseudo ne peut pas être vide"); + } + } + } + + public override bool Equals(object obj) + { + if(ReferenceEquals(obj, null)) return false; + if(ReferenceEquals(obj, this)) return true; + if(GetType() != obj.GetType()) return false; + return Equals(obj as Joueur); + } + + public override int GetHashCode() + { + return HashCode.Combine(id, Id, Pseudo); + } + } +}