Generics and inheritance
am 19.11.2007 13:18:01 von billrSorry if this is the wrong group, but I cna think not of where else to post.
I have an inheritance hierarchy in place as follows ...
PersonVisitor
public interface IPerson
{
string GivenName { get; set; }
string FamilyName { get; set; }
IPerson Clone();
void Visit(PersonVisitor
}
public abstract class PersonVisitor
{
virtual public void Visit(T c) { }
}
public abstract class AlphabeticVisitor
IPerson
{
// class code omited
}
public class FamilyNameVisitor
{
override public void Visit(T c)
{
}
}
Firstly, I would expect that I could pass an object of type
FamilyNameVisitor
Customer c = PeopleFactory.CreateNewCustomer("Marcus", "Barnard");
Assert.IsNotNull(c, "Failed to instantiate the Customer object");
FamilyNameVisitor
c.Visit(v);
However, I am told that this is not possible because an object of type
FamilyNameVisitor
PersonVisitor
sub-class of PersonVisitor
So, I then put the following implicit conversion into the FamilyNameVisitor
class definition
public static implicit operator
PersonVisitor
{
return (v as PersonVisitor
}
but this conversion always returns null :o(
Can somebody please help?
Thanks in advance
--
Of all words of tongue and pen, the saddest are: "It might have been"
Bill.Richards @ greyskin .co .uk
http://greyskin.co.uk