🐛 Initialize empty collections, debug die creation

pull/191/head
Alexis Drai 2 years ago
parent 0a01b402c0
commit 32a58dd414

@ -4,6 +4,6 @@ namespace Data.EF.Dice
{
public class ColorDieEntity : DieEntity
{
public new ICollection<ColorFaceEntity> Faces { get; set; }
public new ICollection<ColorFaceEntity> Faces { get; set; } = new List<ColorFaceEntity>();
}
}

@ -6,19 +6,17 @@ namespace Data.EF.Dice
{
public static class ColorDieExtensions
{
public static ColorDie ToModel(this ColorDieEntity clrDieEntity)
public static ColorDie ToModel(this ColorDieEntity dieEntity)
{
/*
* creating an array of faces model
*/
ColorFace[] faces = new ColorFace[clrDieEntity.Faces.Count - 1];
List<ColorFace> clrFacesList = clrDieEntity.Faces.ToModels().ToList();
clrFacesList.CopyTo(faces, 1);
ColorFace[] faces = dieEntity.Faces.ToModels().ToArray();
/*
* creating the die
*/
ColorDie die = new(clrDieEntity.Faces.ElementAt(0).ToModel(), faces);
ColorDie die = new(faces[0], faces[1..]);
return die;
}

@ -4,6 +4,6 @@ namespace Data.EF.Dice
{
public class ImageDieEntity : DieEntity
{
public new ICollection<ImageFaceEntity> Faces { get; set; }
public new ICollection<ImageFaceEntity> Faces { get; set; } = new List<ImageFaceEntity>();
}
}

@ -1,25 +1,22 @@
using Data.EF.Dice.Faces;
using Model.Dice.Faces;
using Model.Dice;
using Model.Dice.Faces;
namespace Data.EF.Dice
{
public static class ImageDieExtensions
{
public static ImageDie ToModel(this ImageDieEntity clrDieEntity)
public static ImageDie ToModel(this ImageDieEntity dieEntity)
{
/*
* creating an array of faces model
*/
ImageFace[] faces = new ImageFace[clrDieEntity.Faces.Count - 1];
List<ImageFace> clrFacesList = clrDieEntity.Faces.ToModels().ToList();
clrFacesList.CopyTo(faces, 1);
ImageFace[] faces = dieEntity.Faces.ToModels().ToArray();
/*
* creating the die
*/
ImageDie die = new(clrDieEntity.Faces.ElementAt(0).ToModel(), faces);
ImageDie die = new(faces[0], faces[1..]);
return die;
}

@ -4,6 +4,6 @@ namespace Data.EF.Dice
{
public class NumberDieEntity : DieEntity
{
public new ICollection<NumberFaceEntity> Faces { get; set; }
public new ICollection<NumberFaceEntity> Faces { get; set; } = new List<NumberFaceEntity>();
}
}

@ -1,29 +1,22 @@
using Data.EF.Dice.Faces;
using Model.Dice.Faces;
using Model.Dice;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model.Dice.Faces;
namespace Data.EF.Dice
{
public static class NumberDieExtensions
{
public static NumberDie ToModel(this NumberDieEntity clrDieEntity)
public static NumberDie ToModel(this NumberDieEntity dieEntity)
{
/*
* creating an array of faces model
*/
NumberFace[] faces = new NumberFace[clrDieEntity.Faces.Count - 1];
List<NumberFace> clrFacesList = clrDieEntity.Faces.ToModels().ToList();
clrFacesList.CopyTo(faces, 1);
NumberFace[] faces = dieEntity.Faces.ToModels().ToArray();
/*
* creating the die
*/
NumberDie die = new(clrDieEntity.Faces.ElementAt(0).ToModel(), faces);
NumberDie die = new(faces[0], faces[1..]);
return die;
}

Loading…
Cancel
Save