Sorry 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<T<-- AlphabeticVisitor<T<-- FamilyNameVisitor<T>
public interface IPerson
{
string GivenName { get; set; }
string FamilyName { get; set; }
IPerson Clone();
void Visit(PersonVisitor<IPersonvisitor);
}
public abstract class PersonVisitor<Twhere T : IPerson
{
virtual public void Visit(T c) { }
}
public abstract class AlphabeticVisitor<T: PersonVisitor<Twhere T :
IPerson
{
// class code omited
}
public class FamilyNameVisitor<T: AlphabeticVisitor<Twhere T : IPerson
{
override public void Visit(T c)
{
}
}
Firstly, I would expect that I could pass an object of type
FamilyNameVisitor<Tas follows
Customer c = PeopleFactory.CreateNewCustomer("Marcus", "Barnard");
Assert.IsNotNull(c, "Failed to instantiate the Customer object");
FamilyNameVisitor<Customerv = new FamilyNameVisitor<Customer>();
c.Visit(v);
However, I am told that this is not possible because an object of type
FamilyNameVisitor<Customercannot be converted to type
PersonVisitor<IPerson(even though FamilyNameVisitor<Customeris a
sub-class of PersonVisitor<IPerson>, AND Customer is a sub-class of IPerson)
So, I then put the following implicit conversion into the FamilyNameVisitor
class definition
public static implicit operator
PersonVisitor<IPerson>(FamilyNameVisitor<Tv)
{
return (v as PersonVisitor<IPerson>);
}
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