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 <-- AlphabeticVisit or<T<-- FamilyNameVisit or<T>
public interface IPerson
{
string GivenName { get; set; }
string FamilyName { get; set; }
IPerson Clone();
void Visit(PersonVis itor<IPersonvis itor);
}
public abstract class PersonVisitor<T where T : IPerson
{
virtual public void Visit(T c) { }
}
public abstract class AlphabeticVisit or<T: PersonVisitor<T where T :
IPerson
{
// class code omited
}
public class FamilyNameVisit or<T: AlphabeticVisit or<Twhere T : IPerson
{
override public void Visit(T c)
{
}
}
Firstly, I would expect that I could pass an object of type
FamilyNameVisit or<Tas follows
Customer c = PeopleFactory.C reateNewCustome r("Marcus", "Barnard");
Assert.IsNotNul l(c, "Failed to instantiate the Customer object");
FamilyNameVisit or<Customerv = new FamilyNameVisit or<Customer>();
c.Visit(v);
However, I am told that this is not possible because an object of type
FamilyNameVisit or<Customercann ot be converted to type
PersonVisitor<I Person(even though FamilyNameVisit or<Customeris a
sub-class of PersonVisitor<I Person>, AND Customer is a sub-class of IPerson)
So, I then put the following implicit conversion into the FamilyNameVisit or
class definition
public static implicit operator
PersonVisitor<I Person>(FamilyN ameVisitor<Tv)
{
return (v as PersonVisitor<I Person>);
}
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