You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.3 KiB
58 lines
2.3 KiB
using DTOs;
|
|
using Entities;
|
|
using Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ExtensionsClassLibrairie
|
|
{
|
|
/// <summary>
|
|
/// define some methods to manipulate entity, model and dto players :
|
|
/// convert model to DTO, model to Entity, ...
|
|
/// and equality protocols
|
|
/// </summary>
|
|
public static class PlayerExtensionMethods
|
|
{
|
|
// conversion methods
|
|
public static Player ToModel(this PlayerEntity p)
|
|
=> new Player(p.Nickname, p.HashedPassword, p.Id);
|
|
public static Player ToModel(this PlayerDto p)
|
|
=> new Player(p.Nickname, p.HashedPassword, p.Id);
|
|
public static PlayerDto ToDto(this Player p)
|
|
=> new PlayerDto { Id = p.Id, Nickname = p.Nickname, HashedPassword = p.HashedPassword};
|
|
public static PlayerEntity ToEntity(this Player p)
|
|
=> new PlayerEntity { Id = p.Id, Nickname = p.Nickname, HashedPassword = p.HashedPassword };
|
|
|
|
// reuse other methods
|
|
public static PlayerDto ToDto(this PlayerEntity p)
|
|
=> p.ToModel().ToDto();
|
|
public static PlayerEntity ToEntity(this PlayerDto p)
|
|
=> p.ToModel().ToEntity();
|
|
|
|
// equality protocols
|
|
public static bool Equals(this Player p1, Player p2)
|
|
=> p1.Nickname == p2.Nickname;
|
|
|
|
// reuse other methods
|
|
public static bool Equals(this Player p1, PlayerDto p2)
|
|
=> p1.Equals(p2.ToModel());
|
|
public static bool Equals(this Player p1, PlayerEntity p2)
|
|
=> p1.Equals(p2.ToModel());
|
|
public static bool Equals(this PlayerDto p1, Player p2)
|
|
=> p1.ToModel().Equals(p2);
|
|
public static bool Equals(this PlayerDto p1, PlayerDto p2)
|
|
=> p1.ToModel().Equals(p2.ToModel());
|
|
public static bool Equals(this PlayerDto p1, PlayerEntity p2)
|
|
=> p1.ToModel().Equals(p2.ToModel());
|
|
public static bool Equals(this PlayerEntity p1, Player p2)
|
|
=> p1.ToModel().Equals(p2);
|
|
public static bool Equals(this PlayerEntity p1, PlayerDto p2)
|
|
=> p1.ToModel().Equals(p2.ToModel());
|
|
public static bool Equals(this PlayerEntity p1, PlayerEntity p2)
|
|
=> p1.ToModel().Equals(p2.ToModel());
|
|
}
|
|
}
|