Re: getting container element type with reflection
- From: "colin" <colin.rowe1@xxxxxxxxxxxxxxxxxx>
- Date: Mon, 19 Nov 2007 16:15:08 GMT
"Marc Gravell" <marc.gravell@xxxxxxxxx> wrote in message
news:eTKcuUsKIHA.280@xxxxxxxxxxxxxxxxxxxxxxx
Like so:
Type unknownType = typeof(List<string>); // pretend we don't
know this ;-p
foreach (Type intType in unknownType.GetInterfaces()) {
if (intType.IsGenericType &&
intType.GetGenericTypeDefinition()
== typeof(IList<>)) {
Type elementType = intType.GetGenericArguments()[0]; //
****
Trace.WriteLine("Implements IList<T> for T = " +
elementType.FullName);
}
}
At the line marked "****" we have the element-type.
Marc
cool thanks, I didnt understand it at first,
but i tried it and although I had only implmented the non generic
collection in my wrapper, just adding the IList<T>
and letting it implement it with defualt members
it finds the type of 'T' :D
Colin =^.^=
.
- Follow-Ups:
- Re: getting container element type with reflection
- From: Marc Gravell
- Re: getting container element type with reflection
- References:
- getting container element type with reflection
- From: colin
- Re: getting container element type with reflection
- From: Marc Gravell
- Re: getting container element type with reflection
- From: colin
- Re: getting container element type with reflection
- From: Marc Gravell
- getting container element type with reflection
- Prev by Date: Re: what is the best datatype for..
- Next by Date: Re: Generics and inheritance
- Previous by thread: Re: getting container element type with reflection
- Next by thread: Re: getting container element type with reflection
- Index(es):