Prev | Current Page 192 | Next

Jon Skeet

"C# in Depth: What you need to master C# 2 and 3"

See the MSDN documentation for Type.IsGenericType for a suitably
convoluted example.
For reference, here??™s the output of listing 3.10:
System.Int32
System.Collections.Generic.List`1[T]
System.Collections.Generic.Dictionary`2[TKey,TValue]
System.Collections.Generic.List`1[System.Int32]
System.Collections.Generic.Dictionary`2[System.String,System.Int32]
System.Collections.Generic.List`1[System.Int64]
System.Collections.Generic.Dictionary`2[System.Int64,System.Guid]
Having retrieved an object representing a generic type, there are many ???next steps???
you can take. All the previously available ones (finding the members of the type, creating
an instance, and so on) are still present??”although some are not applicable for
Listing 3.10 Using the typeof operator with type parameters
Displays method??™s
type parameter
Displays
generic
types Displays closed
types (despite
using type
parameter)
B
Displays
closed types
94 CHAPTER 3 Parameterized typing with generics
generic type definitions??”and there are new ones as well that let you inquire about the
generic nature of the type.
METHODS AND PROPERTIES OF SYSTEM.TYPE
There are far too many new methods and properties to look at them all in detail, but
there are two particularly important ones: GetGenericTypeDefinition and Make-
GenericType. They are effectively opposites??”the first acts on a constructed type,
retrieving the generic type definition; the second acts on a generic type definition and
returns a constructed type.


Pages:
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204