Obtaining a Type Reference Using System.Type.GetType()
To obtain type information in a more flexible manner, you may call the static GetType() member of
the System.Type class and specify the fully qualified string name of the type you are interested in
examining. Using this approach, you do
not need to have compile-time knowledge of the type you
are extracting metadata from, given that Type.GetType() takes an instance of the omnipresent
System.String.
■
Note
When I say you do not need compile-time knowledge when calling
Type.GetType()
, I am referring to
the fact that this method can take any string value whatsoever (rather than a strongly typed variable). Of course,
you would still need to know the name of the type in a stringified format!
The Type.GetType() method has been overloaded to allow you to specify two Boolean parame-
ters, one of which controls whether an exception should be thrown if the type cannot be found, and
the other of which establishes the case sensitivity of the string. To illustrate, ponder the following:
Do'stlaringiz bilan baham: |