Subclassing ReadOnlyListBase?

Subclassing ReadOnlyListBase?

Old forum URL: forums.lhotka.net/forums/t/3933.aspx


ianinspain posted on Thursday, November 22, 2007

Hi there,

can anyone tell me if i am subclassing ReadOnlyListBase correctly, i am doing it like so

public abstract class BOReadOnlyListBase<T, C> : ReadOnlyListBase<T, C>
        where T : ReadOnlyListBase<T>
        where C : ReadOnlyListBase<C>

The reason i ask is i have seen others only supply Where T: ...........

and also where C: is an interface..

Also another thing that is confusing me is... the where clause should be the base class that i have inherited from .. i.e. ReadOnlyListBase and not BOReadOnlyListBase (my subclass)

Can anyone confirm which is the correct syntax, from what the compiler is telling me they are seem to work... but in the case of not supply the where clause for C... what implications does this have?

Thanks in advance

Ian

ianinspain replied on Thursday, November 22, 2007

Also in EditableRootListBase .. T is assigned to interface

 [Serializable()]
    public abstract class BOEditableRootListBase<T> : Csla.EditableRootListBase<T>
        where T : EditableRootListBase
    {
    }

but i presume i can assign my where T back to the base class??

Thanks agian

McManus replied on Thursday, November 22, 2007

Ian,

The correct way is as follows:

[Serializable()]
public abstract class BOReadOnlyListBase<T,C> : Csla.ReadOnlyListBase<T,C>
   where T : BOReadOnlyListBase<T,C>
{
}

You don't need a restriction here, because Csla.ReadOnlyListBase<T,C> doesn't define a restriction on C either.

[Serializable()]
public abstract class BOEditableRootListBase<T> : Csla.EditableRootListBase<T>
   where T : BOEditableRootListBase<T>
{
}

Hope this helps,

Cheers,
Herman

Copyright (c) Marimer LLC