I'm not expert, in anybody's book, but I believe you're trying to use an
interface like a base class. An interface is really just a signature, a
template if you will. It does not represent inheritance. Trying to cast an
object to it's interface well, that would be like trying to turn a person
into a painting. It can't be done without breaking a few laws of nature not
to mention Newtonian physics. But you can turn a person into a child, or
senior citizen or mammal or vertebrate. A picture of a person is really just
a plan, a image of a three dimensional entity.
Try not using an interface as a generics type. Below was my testing rig.
But I maybe way off here.
DC
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Collections.Generic;
using System.Text;
namespace InterfaceTesting
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("Testing Inheritance");
Manager m1 = new Manager();
m1.Name = "Manager M1";
System.Console.WriteLine("1:" + m1.Name);
Person p1 = (Person)m1;
System.Console.WriteLine("2:" + p1.Name);
List<Manager> Managers = new List<Manager>();
List<Person> Persons = new List<Person>();
List<Pet> Pets = new List<Pet>();
Manager m2 = new Manager();
m2.Name = "Manager M2";
Managers.Add(m2);
Persons.Add(m2);
//Pets.Add(m2); // although Pet implements IMammal you can't
turn a manager into a pet - as much as we'd like to sometimes.
System.Threading.Thread.CurrentThread.Suspend();
}
}
interface IMammal
{
}
class Pet : IMammal
{
public string Name = String.Empty;
}
class Person : IMammal
{
public string Name = String.Empty;
}
class Manager : Person
{
public string Title = String.Empty;
}
}
[Non-text portions of this message have been removed]