Re: Dynamic cast with generics
- From: "Néstor Sánchez A." <nestor.sanchez@xxxxxxxx>
- Date: Mon, 29 Jan 2007 15:02:45 -0400
....the problem is that I don't know that is the derived type used.
The scenario is the following...
I have a namespace with types and classes that defines a business model.
Then, in another namespace, I have the presentation layer where I only need
to know the base types just to show values thru polymorphism (i.e:
AnObject.ToString()).
In other words, at the caller level there is irrelevant any detailed
(derived) information, but still there is need to reference the objects...
how?.
Thanks,
Néstor.
"Marc Gravell" <marc.gravell@xxxxxxxxx> escribió en el mensaje
news:OwSpsg3QHHA.3444@xxxxxxxxxxxxxxxxxxxxxxx
If you are using generics, then *use* generics. For instance:
public void TheCall<T>(T AnObject) where T : BaseClass {...}
public void TheProcess<T>(DerivedClass<T> Value) where T : BaseClass {...}
As you say, another option is reflection - but this should be a last ditch
solution. Is there a (good) reason why you can't use the above? As the
answer to this may influence the best answer...
Marc
.
- Follow-Ups:
- Re: Dynamic cast with generics
- From: Marc Gravell
- Re: Dynamic cast with generics
- References:
- Dynamic cast with generics
- From: Néstor Sánchez
- Re: Dynamic cast with generics
- From: Marc Gravell
- Dynamic cast with generics
- Prev by Date: Re: C# inheritance broken?
- Next by Date: Smart Slicing Routine!!
- Previous by thread: Re: Dynamic cast with generics
- Next by thread: Re: Dynamic cast with generics
- Index(es):
Relevant Pages
|