<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FReflection%2FType</id>
		<title>Csharp/C Sharp/Reflection/Type - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FC_Sharp%2FReflection%2FType"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Reflection/Type&amp;action=history"/>
		<updated>2026-04-29T23:50:33Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Reflection/Type&amp;diff=364&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Reflection/Type&amp;diff=364&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:18Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/C_Sharp/Reflection/Type&amp;diff=365&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/C_Sharp/Reflection/Type&amp;diff=365&amp;oldid=prev"/>
				<updated>2010-05-26T11:38:13Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Call GetType for int data type==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
   &lt;br /&gt;
class TypeObjectFromInstanceApp&lt;br /&gt;
{&lt;br /&gt;
    public static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        int i = 6;&lt;br /&gt;
        Type type = i.GetType();&lt;br /&gt;
        Console.WriteLine(type.Name);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Call GetType() from StringBuilder==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
class MainClass{&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            StringBuilder sb = new StringBuilder();&lt;br /&gt;
            Type t6 = sb.GetType();&lt;br /&gt;
       }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Call static method GetType from Type to get the Type instance==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Text;&lt;br /&gt;
class MainClass{&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            Type t2 = Type.GetType(&amp;quot;System.String&amp;quot;);&lt;br /&gt;
            Type t3 = Type.GetType(&amp;quot;System.String&amp;quot;, true);&lt;br /&gt;
            Type t4 = Type.GetType(&amp;quot;system.string&amp;quot;, true, true);&lt;br /&gt;
            Type t5 = Type.GetType(&amp;quot;System.Data.DataSet, System.Data,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&amp;quot;);&lt;br /&gt;
       }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Deeper Reflection:Listing All the Types in an Assembly==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
A Programmer&amp;quot;s Introduction to C# (Second Edition)&lt;br /&gt;
by Eric Gunnerson&lt;br /&gt;
Publisher: Apress  L.P.&lt;br /&gt;
ISBN: 1-893115-62-3&lt;br /&gt;
*/&lt;br /&gt;
// 36 - Deeper into C#\Deeper Reflection\Listing All the Types in an Assembly&lt;br /&gt;
// copyright 2000 Eric Gunnerson&lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
enum MyEnum&lt;br /&gt;
{&lt;br /&gt;
    Val1,&lt;br /&gt;
    Val2,&lt;br /&gt;
    Val3&lt;br /&gt;
}&lt;br /&gt;
class MyClass&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
struct MyStruct&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
public class ListingAlltheTypesinanAssembly&lt;br /&gt;
{&lt;br /&gt;
    public static void Main(String[] args)&lt;br /&gt;
    {&lt;br /&gt;
        // list all types in the assembly that is passed&lt;br /&gt;
        // in as a parameter&lt;br /&gt;
        Assembly a = Assembly.LoadFrom (args[0]);&lt;br /&gt;
        Type[] types = a.GetTypes();&lt;br /&gt;
        &lt;br /&gt;
        // look through each type, and write out some information&lt;br /&gt;
        // about them.&lt;br /&gt;
        foreach (Type t in types)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine (&amp;quot;Name: {0}&amp;quot;, t.FullName);&lt;br /&gt;
            Console.WriteLine (&amp;quot;Namespace: {0}&amp;quot;, t.Namespace);&lt;br /&gt;
            Console.WriteLine (&amp;quot;Base Class: {0}&amp;quot;, t.BaseType.FullName);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==demonstrates both the instance and static GetType methods==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
&lt;br /&gt;
class MyClass&amp;lt;K, V&amp;gt; {&lt;br /&gt;
    public void FunctionA(K argk, V argv) {&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
class XClass&amp;lt;T&amp;gt; {&lt;br /&gt;
    public void FunctionB(T argt) {&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
class Starter {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        MyClass&amp;lt;int, decimal&amp;gt; obj = new MyClass&amp;lt;int, decimal&amp;gt;();&lt;br /&gt;
        Type typeClosed = obj.GetType();&lt;br /&gt;
        Console.WriteLine(typeClosed.ToString());&lt;br /&gt;
        Type typeOpen = Type.GetType(&amp;quot;CSharpBook.XClass`1&amp;quot;);&lt;br /&gt;
        Console.WriteLine(typeOpen.ToString());&lt;br /&gt;
        Type typeClosed2 = Type.GetType(&lt;br /&gt;
            &amp;quot;CSharpBook.MyClass`2[System.Int32, System.Decimal]&amp;quot;);&lt;br /&gt;
        Console.WriteLine(typeClosed2.ToString());&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining the base classes and interfaces for a class.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
class MainClass {&lt;br /&gt;
    public static void Main(string[] args) {&lt;br /&gt;
        if (args.Length &amp;gt;= 2)&lt;br /&gt;
            CheckBaseClass(args[0], args[1]);&lt;br /&gt;
    }&lt;br /&gt;
    public static void CheckBaseClass(string AssemblyName,string ClassName) {&lt;br /&gt;
        Assembly assembly = Assembly.LoadFrom(AssemblyName);&lt;br /&gt;
        if (assembly == null) {&lt;br /&gt;
            Console.WriteLine(&amp;quot;Unable to open {0}&amp;quot;,AssemblyName);&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        foreach (Type t in assembly.GetTypes()) {&lt;br /&gt;
            if (t.IsClass == false)&lt;br /&gt;
                continue;&lt;br /&gt;
            Type baseType = t.BaseType;&lt;br /&gt;
            while (baseType != null) {&lt;br /&gt;
                if (baseType.FullName.EndsWith(ClassName)) {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Class {0} is derived from {1}&amp;quot;,t.FullName, ClassName);&lt;br /&gt;
                }&lt;br /&gt;
                baseType = baseType.BaseType;&lt;br /&gt;
            }&lt;br /&gt;
            Type[] intfc = t.GetInterfaces();&lt;br /&gt;
            foreach (Type itf in intfc) {&lt;br /&gt;
                if (itf.FullName.EndsWith(ClassName)) {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Class {0} is derived from intf {1}&amp;quot;,t.FullName, ClassName);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Generic methods, like nongeneric methods, can be invoked dynamically at run time.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
&lt;br /&gt;
public class GenericZ&amp;lt;K, V, Z&amp;gt;&lt;br /&gt;
    where K : new()&lt;br /&gt;
    where V : new() {&lt;br /&gt;
    public void MethodA&amp;lt;A&amp;gt;(A argument1, Z argument2) {&lt;br /&gt;
        Console.WriteLine(&amp;quot;MethodA invoked&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    private K field1 = new K();&lt;br /&gt;
    private V field2 = new V();&lt;br /&gt;
}&lt;br /&gt;
class Starter {&lt;br /&gt;
    static void Main() {&lt;br /&gt;
        Type genericType = typeof(GenericZ&amp;lt;,,&amp;gt;);&lt;br /&gt;
        Type[] parameters ={typeof(int),typeof(float),&lt;br /&gt;
                typeof(int)};&lt;br /&gt;
        Type closedType = genericType.MakeGenericType(parameters);&lt;br /&gt;
        MethodInfo openMethod = closedType.GetMethod(&amp;quot;MethodA&amp;quot;);&lt;br /&gt;
        object newObject = Activator.CreateInstance(closedType);&lt;br /&gt;
        parameters = new Type[] { typeof(int) };&lt;br /&gt;
        MethodInfo closedMethod =&lt;br /&gt;
            openMethod.MakeGenericMethod(parameters);&lt;br /&gt;
        object[] methodargs = { 2, 10 };&lt;br /&gt;
        closedMethod.Invoke(newObject, methodargs);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Get Generic Type Definition==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
&lt;br /&gt;
class MyClass&amp;lt;K, V&amp;gt; {&lt;br /&gt;
    public void FunctionA(K argk, V argv) {&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
class Starter {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        MyClass&amp;lt;int, decimal&amp;gt; obj = new MyClass&amp;lt;int, decimal&amp;gt;();&lt;br /&gt;
        MyClass&amp;lt;string, float&amp;gt; obj2 = new MyClass&amp;lt;string, float&amp;gt;();&lt;br /&gt;
        Type closedType = obj.GetType();&lt;br /&gt;
        Type openType = closedType.GetGenericTypeDefinition();&lt;br /&gt;
        Type closedType2 = obj2.GetType();&lt;br /&gt;
        Type openType2 = closedType2.GetGenericTypeDefinition();&lt;br /&gt;
        Console.WriteLine(openType.ToString());&lt;br /&gt;
        Console.WriteLine(openType2.ToString());&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Get object Type Name, UnderlyingSystemType, IsClass==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
class InstanceType&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
    String myVar = &amp;quot;P&amp;quot;;&lt;br /&gt;
    Type t = myVar.GetType();&lt;br /&gt;
    Console.WriteLine(&amp;quot;Name : {0}&amp;quot;,t.Name);&lt;br /&gt;
    Console.WriteLine(&amp;quot;Underlying System Type : {0}&amp;quot;,t.UnderlyingSystemType);&lt;br /&gt;
    Console.WriteLine(&amp;quot;Is Class : {0}&amp;quot;,t.IsClass);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Illustrates runtime type creation==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Mastering Visual C# .NET&lt;br /&gt;
by Jason Price, Mike Gunderloy&lt;br /&gt;
Publisher: Sybex;&lt;br /&gt;
ISBN: 0782129110&lt;br /&gt;
*/&lt;br /&gt;
/*&lt;br /&gt;
  Example17_7 illustrates runtime type creation&lt;br /&gt;
*/&lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
using System.Reflection.Emit;&lt;br /&gt;
public class Example17_7 &lt;br /&gt;
{&lt;br /&gt;
    public static void Main() &lt;br /&gt;
    {&lt;br /&gt;
        // get the current appdomain&lt;br /&gt;
        AppDomain ad = AppDomain.CurrentDomain;&lt;br /&gt;
        // create a new dynamic assembly&lt;br /&gt;
        AssemblyName an = new AssemblyName();&lt;br /&gt;
        an.Name = &amp;quot;DynamicRandomAssembly&amp;quot;;&lt;br /&gt;
        AssemblyBuilder ab = ad.DefineDynamicAssembly(&lt;br /&gt;
         an, AssemblyBuilderAccess.Run);&lt;br /&gt;
        // create a new module to hold code in the assembly&lt;br /&gt;
        ModuleBuilder mb = ab.DefineDynamicModule(&amp;quot;RandomModule&amp;quot;);&lt;br /&gt;
        // create a type in the module&lt;br /&gt;
        TypeBuilder tb = mb.DefineType(&lt;br /&gt;
         &amp;quot;DynamicRandomClass&amp;quot;,TypeAttributes.Public);&lt;br /&gt;
        // create a method of the type&lt;br /&gt;
        Type returntype = typeof(int);&lt;br /&gt;
        Type[] paramstype = new Type[0];&lt;br /&gt;
        MethodBuilder methb=tb.DefineMethod(&amp;quot;DynamicRandomMethod&amp;quot;, &lt;br /&gt;
         MethodAttributes.Public, returntype, paramstype);&lt;br /&gt;
        // generate the MSIL&lt;br /&gt;
        ILGenerator gen = methb.GetILGenerator();&lt;br /&gt;
        gen.Emit(OpCodes.Ldc_I4, 1);&lt;br /&gt;
        gen.Emit(OpCodes.Ret);&lt;br /&gt;
        // finish creating the type and make it available&lt;br /&gt;
        Type t = tb.CreateType();&lt;br /&gt;
        // create an instance of the new type&lt;br /&gt;
        Object o = Activator.CreateInstance(t);&lt;br /&gt;
        // create an empty arguments array&lt;br /&gt;
        Object[] aa = new Object[0];&lt;br /&gt;
        // get the method and invoke it&lt;br /&gt;
        MethodInfo m = t.GetMethod(&amp;quot;DynamicRandomMethod&amp;quot;);&lt;br /&gt;
        int i = (int) m.Invoke(o, aa);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Method {0} in Class {1} returned {2}&amp;quot;,&lt;br /&gt;
            m, t, i);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
//=============================================================&lt;br /&gt;
using System;&lt;br /&gt;
public class DynamicRandomClass&lt;br /&gt;
{&lt;br /&gt;
    public int DynamicRandomMethod()&lt;br /&gt;
    {&lt;br /&gt;
        return 1;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==IsGeneric and IsGenericTypeDefinition==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
public class MyClass&amp;lt;T, V&amp;gt; {&lt;br /&gt;
    public T membera;&lt;br /&gt;
}&lt;br /&gt;
public class XClass {&lt;br /&gt;
    public void MethodA&amp;lt;T&amp;gt;() {&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
class Starter {&lt;br /&gt;
    static void Main() {&lt;br /&gt;
        Type[] types = { typeof(MyClass&amp;lt;,&amp;gt;), typeof(MyClass&amp;lt;int, int&amp;gt;) };&lt;br /&gt;
        bool[,] bresp = { {types[0].IsGenericType,&lt;br /&gt;
                               types[0].IsGenericTypeDefinition},&lt;br /&gt;
                              {types[1].IsGenericType,&lt;br /&gt;
                               types[1].IsGenericTypeDefinition}};&lt;br /&gt;
        Console.WriteLine(&amp;quot;Is MyClass&amp;lt;,&amp;gt; a generic type? &amp;quot; + bresp[0, 0]);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Is MyClass&amp;lt;,&amp;gt; open? &amp;quot; + bresp[0, 1]);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Is MyClass&amp;lt;int,int&amp;gt; a generic type? &amp;quot; + bresp[1, 0]);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Is MyClass&amp;lt;int,int&amp;gt; open? &amp;quot; + bresp[1, 1]);&lt;br /&gt;
        Type tObj = typeof(XClass);&lt;br /&gt;
        MethodInfo method = tObj.GetMethod(&amp;quot;MethodA&amp;quot;);&lt;br /&gt;
        bool[] bMethod ={method.IsGenericMethod, method.IsGenericMethodDefinition};&lt;br /&gt;
        Console.WriteLine(&amp;quot;Is XClass.MethodA&amp;lt;T&amp;gt; a generic method? &amp;quot; + bMethod[0]);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Is XClass.MethodA&amp;lt;T&amp;gt; open? &amp;quot; + bMethod[1]);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Print Types==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
public class MainClass{&lt;br /&gt;
    public static void Main(){&lt;br /&gt;
        Assembly LoadedAsm = Assembly.LoadFrom(&amp;quot;yourName&amp;quot;);&lt;br /&gt;
        Console.WriteLine(LoadedAsm.FullName);&lt;br /&gt;
        Type[] LoadedTypes = LoadedAsm.GetTypes();&lt;br /&gt;
        if (LoadedTypes.Length == 0) {&lt;br /&gt;
            Console.WriteLine(&amp;quot;No Types!&amp;quot;);&lt;br /&gt;
        } else {&lt;br /&gt;
            foreach (Type t in LoadedTypes) {&lt;br /&gt;
                if (t.IsPublic) {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Public &amp;quot;);&lt;br /&gt;
                } else if (t.IsNestedPublic) {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Public Nested &amp;quot;);&lt;br /&gt;
                } else {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Not Public &amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
                if (t.IsEnum) {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Enum: &amp;quot;);&lt;br /&gt;
                } else if (t.IsValueType) {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Struct: &amp;quot;);&lt;br /&gt;
                } else {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;Class: &amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
                Console.WriteLine(&amp;quot;{0}&amp;quot;, t.FullName);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Query properties of a Type==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
   &lt;br /&gt;
class QueryTypesApp&lt;br /&gt;
{&lt;br /&gt;
    public static void DisplaySyntax()&lt;br /&gt;
    {&lt;br /&gt;
        Console.WriteLine(&amp;quot;\nSyntax: QueryTypes &amp;lt;typename&amp;gt;\n&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
   &lt;br /&gt;
    public static void QueryType(string typename)&lt;br /&gt;
    {&lt;br /&gt;
        try&lt;br /&gt;
        {&lt;br /&gt;
            Type type = Type.GetType(typename, true, true);&lt;br /&gt;
   &lt;br /&gt;
            Console.WriteLine(&amp;quot;Type name: {0}&amp;quot;, type.FullName);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tHasElementType = {0}&amp;quot;, type.HasElementType);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsAbstract = {0}&amp;quot;, type.IsAbstract);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsAnsiClass = {0}&amp;quot;, type.IsAnsiClass);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsArray = {0}&amp;quot;, type.IsArray);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsAutoClass = {0}&amp;quot;, type.IsAutoClass);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsAutoLayout = {0}&amp;quot;, type.IsAutoLayout);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsByRef = {0}&amp;quot;, type.IsByRef);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsClass = {0}&amp;quot;, type.IsClass);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsCOMObject = {0}&amp;quot;,type.IsCOMObject);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsContextful = {0}&amp;quot;, type.IsContextful);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsEnum = {0}&amp;quot;, type.IsEnum);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsExplicitLayout = {0}&amp;quot;,type.IsExplicitLayout);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsImport = {0}&amp;quot;, type.IsImport);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsInterface = {0}&amp;quot;, type.IsInterface);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsLayoutSequential = {0}&amp;quot;, type.IsLayoutSequential);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsMarshalByRef = {0}&amp;quot;, type.IsMarshalByRef);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsNestedAssembly = {0}&amp;quot;,type.IsNestedAssembly);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsNestedFamANDAssem = {0}&amp;quot;, type.IsNestedFamANDAssem);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsNestedFamily = {0}&amp;quot;, type.IsNestedFamily);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsNestedFamORAssem = {0}&amp;quot;,type.IsNestedFamORAssem);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsNestedPrivate = {0}&amp;quot;, type.IsNestedPrivate);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsNestedPublic = {0}&amp;quot;, type.IsNestedPublic);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsNotPublic = {0}&amp;quot;, type.IsNotPublic);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsPointer = {0}&amp;quot;, type.IsPointer);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsPrimitive = {0}&amp;quot;, type.IsPrimitive);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsPublic = {0}&amp;quot;, type.IsPublic);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsSealed = {0}&amp;quot;, type.IsSealed);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsSerializable = {0}&amp;quot;, type.IsSerializable);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsSpecialName = {0}&amp;quot;,type.IsSpecialName);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsUnicodeClass = {0}&amp;quot;, type.IsUnicodeClass);&lt;br /&gt;
            Console.WriteLine(&amp;quot;\tIsValueType = {0}&amp;quot;, type.IsValueType);&lt;br /&gt;
        }&lt;br /&gt;
        catch(System.TypeLoadException e)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;{0} is not a valid type&amp;quot;,&lt;br /&gt;
                 typename);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
   &lt;br /&gt;
    public static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        if (1 != args.Length) DisplaySyntax();&lt;br /&gt;
        else QueryType(args[0]);&lt;br /&gt;
   &lt;br /&gt;
        Console.ReadLine();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The typeName parameter is a combination of the Assembly and Type names==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
class ReflectOnlyType {&lt;br /&gt;
    static void Main() {&lt;br /&gt;
        Type zType = Type.ReflectionOnlyGetType(&amp;quot;ReflectOnlyType&amp;quot;, false, false);&lt;br /&gt;
        Console.WriteLine(zType.Name);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Type.GetConstructors==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
public class Class1 {&lt;br /&gt;
    public static int Main() {&lt;br /&gt;
        Type t = typeof(MyClass);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Type of class: &amp;quot; + t);&lt;br /&gt;
        Console.WriteLine(&amp;quot;Namespace: &amp;quot; + t.Namespace);&lt;br /&gt;
        ConstructorInfo[] ci = t.GetConstructors();&lt;br /&gt;
        Console.WriteLine(&amp;quot;Constructors are:&amp;quot;);&lt;br /&gt;
        foreach (ConstructorInfo i in ci) {&lt;br /&gt;
            Console.WriteLine(i);&lt;br /&gt;
        }&lt;br /&gt;
        return 0;&lt;br /&gt;
    }&lt;br /&gt;
    public class MyClass {&lt;br /&gt;
        public int pubInteger;&lt;br /&gt;
        private int _privValue;&lt;br /&gt;
        public MyClass() {&lt;br /&gt;
        }&lt;br /&gt;
        public MyClass(int IntegerValueIn) {&lt;br /&gt;
            pubInteger = IntegerValueIn;&lt;br /&gt;
        }&lt;br /&gt;
        public int Add10(int IntegerValueIn) {&lt;br /&gt;
            Console.WriteLine(IntegerValueIn);&lt;br /&gt;
            return IntegerValueIn + 10;&lt;br /&gt;
        }&lt;br /&gt;
        public int TestProperty {&lt;br /&gt;
            get {&lt;br /&gt;
                return _privValue;&lt;br /&gt;
            }&lt;br /&gt;
            set {&lt;br /&gt;
                _privValue = value;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Type.GetGenericArguments and MethodInfo.GetGenericArguments:==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
&lt;br /&gt;
class MyClass&amp;lt;K, V&amp;gt; {&lt;br /&gt;
    public void FunctionA(K argk, V argv) {&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
class Starter {&lt;br /&gt;
    public static void Main() {&lt;br /&gt;
        MyClass&amp;lt;int, decimal&amp;gt; obj = new MyClass&amp;lt;int, decimal&amp;gt;();&lt;br /&gt;
        MyClass&amp;lt;string, float&amp;gt; obj2 = new MyClass&amp;lt;string, float&amp;gt;();&lt;br /&gt;
        Type closedType = obj.GetType();&lt;br /&gt;
        Type openType = closedType.GetGenericTypeDefinition();&lt;br /&gt;
        Type closedType2 = obj2.GetType();&lt;br /&gt;
        Type openType2 = closedType2.GetGenericTypeDefinition();&lt;br /&gt;
        Console.WriteLine(openType.ToString());&lt;br /&gt;
        Console.WriteLine(openType2.ToString());&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use GetCustomAttributes from Type to get custom attributes==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]&lt;br /&gt;
public class AuthorAttribute : System.Attribute&lt;br /&gt;
{&lt;br /&gt;
    private string company; // Creator&amp;quot;s company&lt;br /&gt;
    private string name;    // Creator&amp;quot;s name&lt;br /&gt;
    public AuthorAttribute(string name)&lt;br /&gt;
    {&lt;br /&gt;
        this.name = name;&lt;br /&gt;
        company = &amp;quot;&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    public string Company&lt;br /&gt;
    {&lt;br /&gt;
        get { return company; }&lt;br /&gt;
        set { company = value; }&lt;br /&gt;
    }&lt;br /&gt;
    public string Name&lt;br /&gt;
    {&lt;br /&gt;
        get { return name; }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[assembly: Author(&amp;quot;Allen&amp;quot;, Company = &amp;quot;Ltd.&amp;quot;)]&lt;br /&gt;
[Author(&amp;quot;Allen&amp;quot;, Company = &amp;quot;Objective Ltd.&amp;quot;)]&lt;br /&gt;
class SomeClass { }&lt;br /&gt;
[Author(&amp;quot;Lena&amp;quot;)]&lt;br /&gt;
public class SomeOtherClass&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
[Author(&amp;quot;FirstName&amp;quot;)]&lt;br /&gt;
[Author(&amp;quot;Allen&amp;quot;, Company = &amp;quot;Ltd.&amp;quot;)]&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        Type type = typeof(MainClass);&lt;br /&gt;
        object[] attrs = type.GetCustomAttributes(typeof(AuthorAttribute), true);&lt;br /&gt;
        foreach (AuthorAttribute a in attrs)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(a.Name + &amp;quot;, &amp;quot; + a.rupany);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Type.GetType to check the type of an object==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static bool IsType(object obj, string type)&lt;br /&gt;
    {&lt;br /&gt;
        Type t = Type.GetType(type, true, true);&lt;br /&gt;
        return t == obj.GetType() || obj.GetType().IsSubclassOf(t);&lt;br /&gt;
    }&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        Object someObject = new StringReader(&amp;quot;This is a StringReader&amp;quot;);&lt;br /&gt;
        if (typeof(StringReader) == someObject.GetType())&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;typeof: someObject is a StringReader&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        if (IsType(someObject, &amp;quot;System.IO.TextReader&amp;quot;))&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;GetType: someObject is a TextReader&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use Type.IsClass to check if a type is a class==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt; &lt;br /&gt;
using System;&lt;br /&gt;
using System.Reflection;&lt;br /&gt;
class NameType&lt;br /&gt;
{&lt;br /&gt;
  public static void Main()&lt;br /&gt;
  {&lt;br /&gt;
        Type t = Type.GetType(&amp;quot;System.String&amp;quot;);&lt;br /&gt;
    Console.WriteLine(&amp;quot;Name : {0}&amp;quot;,t.Name);&lt;br /&gt;
    Console.WriteLine(&amp;quot;Underlying System Type : {0}&amp;quot;,t.UnderlyingSystemType);&lt;br /&gt;
    Console.WriteLine(&amp;quot;Is Class : {0}&amp;quot;,t.IsClass);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
 &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>