I have the following example relationship:
namespace Yesod
{
public class Program
{
//
//
//
public struct Particle
{
public byte type;
}
//
//
//
public class Entity<T>
{
public Entity<Entity<T>> Parent
{ get; private set; }
//
//
//
public Entity(Entity<Entity<T>> parent)
{
this.Parent = parent;
}
}
//
//
//
public sealed class Atom : Entity<Particle>
{
public Atom(Entity<Atom> parent)
: base(parent) // Compile Error.
{ }
}
//
//
//
public sealed class Molecule : Entity<Atom>
{
public Molecule()
: base(null)
{ }
}
static void Main(string[] args)
{
}
}
}
How would I solve the following compile error that the above produces?
Argument 1: cannot convert from 'Yesod.Program.Entity<Yesod.Program.Atom>' to 'Yesod.Program.Entity<Yesod.Program.Entity<Yesod.Program.Particle>>'
Comment Reply #1: Specifically, the code is trying to assign an object of type
Entity<Atom>
to an object of type
Entity<Entity<Particle>>
as Atom is implemented as
public sealed class Atom : Entity<Particle>
whereby
Entity<Atom>
is expected to breakdown into
Entity<Entity<Particle>>