/// \file ObjetOhara.cs
/// \brief Contient la définition de la classe ObjetOhara.
///
/// La classe ObjetOhara représente les différents objets de notre application Ohara avec leur nom et l'image qui leur est attitré pour pouvoir factoriser le code.
///
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Model.Classes
{
///
/// Représente un objet du monde de One Piece.
///
[DataContract(Name = "objetohara")]
public class ObjetOhara : INotifyPropertyChanged
{
///
/// Événement déclenché lorsque la valeur d'une propriété change.
///
public event PropertyChangedEventHandler? PropertyChanged;
///
/// Obtient ou définit le nom de l'objet.
///
[DataMember(Name = "nom")]
private string? nom;
public string? Nom {
get => nom;
set
{
nom = value;
OnPropertyChanged();
}
}
///
/// Obtient ou définit le chemin de l'image représentant l'objet.
///
[DataMember(Name = "image")]
private string? image;
public string? Image {
get => image;
set
{
image = value;
OnPropertyChanged();
}
}
///
/// Obtient ou définit une valeur indiquant si l'objet est marqué comme favori.
///
[DataMember(Name = "estfavori")]
private bool estfavori;
public bool EstFavori {
get=>estfavori;
set
{
estfavori = value;
}
}
///
/// Initialise une nouvelle instance de la classe avec le nom spécifié.
///
/// Le nom de l'objet.
/// Le chemin de l'image représentant l'objet (par défaut : "baseimage.png").
/// Indique si l'objet est marqué comme favori (par défaut : false).
public ObjetOhara(string nom, string image = "baseimage.png", bool estFavori = false)
{
Nom = nom;
Image = image;
EstFavori = estFavori;
}
///
/// Détermine si l'objet spécifié est égal à l'objet actuel.
///
/// L'objet à comparer avec l'objet actuel.
/// true si les objets sont égaux ; sinon, false.
public override bool Equals(object? obj)
{
if (obj == null) return false;
if (this.GetType() != obj.GetType())
{
return false;
}
else
{
ObjetOhara o = (ObjetOhara)obj;
return o.Nom == Nom;
}
}
///
/// Retourne le code de hachage de l'objet.
///
/// Le code de hachage de l'objet.
public override int GetHashCode()
{
return HashCode.Combine(Nom, Image,EstFavori);
}
///
/// Retourne une chaîne de caractères représentant l'objet actuel.
///
/// Une chaîne de caractères représentant l'objet actuel.
public override string ToString()
{
return "ObjetOhara : " + Nom + " " +EstFavori+ " " + Image;
}
///
/// Déclenche l'événement PropertyChanged.
///
/// Le nom de la propriété qui a changé (facultatif).
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}