On 16.01.2010 15:02, [email protected] wrote: > // test.dll > using System; > namespace Application > { > public class EnclosingClass<A> > { > public class NestedClass<B> : EnclosingClass<A> > { > public class SecondNestedClass<C, D> : NestedClass<B> > { > // > } > } > } > } > > ... > > This program produces the following output: > > Class name: SecondNestedClass > Base class: NestedClass`1 > Parameter name: A, owner: SecondNestedClass`2 > Parameter name: B, owner: SecondNestedClass`2 > > I thought that "owner" should be EnclosingClass`1 and NestedClass`1 > respectively, is this behavior correct ? >
In IL, a nested class cannot use type parameters from outer classes. The
C# compiler will always copy type parameters into nested classes.
So your example compiles into three classes:
class Application.EnclosingClass`1<A> {}
class Application.EnclosingClass`1+NestedClass`1<A, B> {}
class Application.EnclosingClass`1+NestedClass`1+SecondNestedClass`2<A, B, C,
D> {}
To detect the actual owner, you could compare the inner classes' number of type
parameters with the outer classes'. Only those parameters that the inner class
is having additionally are actually belonging to the inner class.
Alternatively, you can infer the distribution of the type parameters onto the
nesting levels from the type name (`n syntax).
Daniel
signature.asc
Description: OpenPGP digital signature
