public T getData() {
return this._data;
}
}
Now, when you compile this class -- whether it's written in VB or C# -- it's going to get compiled into
an IL representation of your generic type. This IL form of your generic type shares many of the concep-
tual traits of a generic class. If you look at the following IL closely, you can see how it introduces specific
extensions that allow it to support the idea of placeholders for each generic type parameter:
.class public auto ansi beforefieldinit TestClass<(object) T>
extends object
{
.field private !0 _data
}
.method public hidebysig specialname rtspecialname instance void .ctor(!0 data)
cil managed
{
// Code Size: 16 byte(s)
.maxstack 8
L_0000: ldarg.0
L_0001: call instance void object::.ctor()
L_0006: nop
L_0007: ldarg.0
L_0008: ldarg.1
L_0009: stfld !0 TestClass`1<!0>::_data
L_000e: nop
L_000f: ret
}
.method public hidebysig instance !0 getData() cil managed
{
// Code Size: 11 byte(s)
.maxstack 1
.locals (!0 local1)
L_0000: ldarg.0
L_0001: ldfld !0 TestClass`1<!0>::_data
L_0006: stloc.0
L_0007: br.s L_0009
L_0009: ldloc.0
L_000a: ret
}
You can see here how the generic characteristics of your class simply carried forward into this IL. To sup-
port this concept, the IL is essentially taking on the same generic constructs that have been added to each
of the .NET languages to support generics. By extending IL in this manner, you can see how it's now
possible to have generic types at run-time.
This one facet of the .NET generics implementation lays the fundamental foundation for all of the effi-
ciencies and Just-in-Time concepts that are supported by .NET generics. It also allows generic types to
participate as first-class citizens within the CLR.
247
Under the Hood
14_559885 ch11.qxd 9/8/05 10:59 PM Page 247
Summary :
extends object { .field private !0 _data } .method public hidebysig specialname rtspecialname instance void .ctor(!0 data) cil managed { // Code Size: 16 byte(s) .maxstack 8 L_0000: ldarg.0 L_0001: call instance void object::.ctor() L_0006: nop L_0007: ldarg.0 L_0008: ldarg.1 L_0009: stfld !0 TestClass`1<!0>::_data L_000e: nop L_000f: ret } .method public hidebysig instance !0 getData() cil managed { // Code Size: 11 byte(s) .maxstack 1 .locals (!0 local1) L_0000: ldarg.0 L_0001: ldfld !0 TestClass`1<!0>::_data L_0006: stloc.0 L_0007: br.s L_0009 L_0009: ldloc.0 L_000a: ret } You can see here how the generic characteristics of your class simply carried forward into this IL.
Tags :
generic,public,class,net,ldarg0,see,l0009,generics,instance,type,support,now,l0006