当前位置: 首页>>代码示例>>C#>>正文


C# Type.FullName属性代码示例

本文整理汇总了C#中System.Type.FullName属性的典型用法代码示例。如果您正苦于以下问题:C# Type.FullName属性的具体用法?C# Type.FullName怎么用?C# Type.FullName使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Type的用法示例。


在下文中一共展示了Type.FullName属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;
class TestFullName 
{
public static void Main() 
    {
    Type t = typeof(Array);
    Console.WriteLine("The full name of the Array type is {0}.", t.FullName);
    }
}
开发者ID:.NET开发者,项目名称:System,代码行数:10,代码来源:Type.FullName

输出:

The full name of the Array type is System.Array.

示例2: Main

//引入命名空间
using System;
using System.Collections.Generic;
using System.Globalization;

public class Example
{
    public static void Main()
    {
        Type t = typeof(String);
        ShowTypeInfo(t);

        t = typeof(List<>);
        ShowTypeInfo(t);

        var list = new List<String>();
        t = list.GetType();
        ShowTypeInfo(t);

        Object v = 12;
        t = v.GetType();
        ShowTypeInfo(t);

        t = typeof(IFormatProvider);
        ShowTypeInfo(t);

        IFormatProvider ifmt = NumberFormatInfo.CurrentInfo;
        t = ifmt.GetType();
        ShowTypeInfo(t);
    }

    private static void ShowTypeInfo(Type t)
    {
        Console.WriteLine($"Name: {t.Name}");
        Console.WriteLine($"Full Name: {t.FullName}");
        Console.WriteLine($"ToString:  {t}");
        Console.WriteLine($"Assembly Qualified Name: {t.AssemblyQualifiedName}");
        Console.WriteLine();
    }
}
开发者ID:.NET开发者,项目名称:System,代码行数:40,代码来源:Type.FullName

输出:

Name: String
Full Name: System.String
ToString:  System.String
Assembly Qualified Name: System.String, mscorlib, Version=4.0.0.0, Culture=neutr
al, PublicKeyToken=b77a5c561934e089

Name: List`1
Full Name: System.Collections.Generic.List`1
ToString:  System.Collections.Generic.List`1[T]
Assembly Qualified Name: System.Collections.Generic.List`1, mscorlib, Version=4.
0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Name: List`1
Full Name: System.Collections.Generic.List`1[[System.String, mscorlib, Version=4
.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
ToString:  System.Collections.Generic.List`1[System.String]
Assembly Qualified Name: System.Collections.Generic.List`1[[System.String, mscor
lib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorl
ib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Name: Int32
Full Name: System.Int32
ToString:  System.Int32
Assembly Qualified Name: System.Int32, mscorlib, Version=4.0.0.0, Culture=neutra
l, PublicKeyToken=b77a5c561934e089

Name: IFormatProvider
Full Name: System.IFormatProvider
ToString:  System.IFormatProvider
Assembly Qualified Name: System.IFormatProvider, mscorlib, Version=4.0.0.0, Cult
ure=neutral, PublicKeyToken=b77a5c561934e089

Name: NumberFormatInfo
Full Name: System.Globalization.NumberFormatInfo
ToString:  System.Globalization.NumberFormatInfo
Assembly Qualified Name: System.Globalization.NumberFormatInfo, mscorlib, Versio
n=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

示例3: Main

//引入命名空间
using System;
using System.Collections.Generic;

public class Example
{
   public static void Main()
   {
      Type t = typeof(List<>);
      Console.WriteLine(t.FullName);
      Console.WriteLine();

      List<String> list = new List<String>();
      t = list.GetType();
      Console.WriteLine(t.FullName);
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:17,代码来源:Type.FullName

输出:

System.Collections.Generic.List`1

System.Collections.Generic.List`1[[System.String, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

示例4: Main

//引入命名空间
using System;
using System.Reflection;

public class Example
{
   public static void Main()
   {
      Type t = typeof(Nullable<>); 
      Console.WriteLine(t.FullName);
      if (t.IsGenericType) {
         Console.Write("   Generic Type Parameters: ");
         Type[] gtArgs = t.GetGenericArguments();
         for (int ctr = 0; ctr < gtArgs.Length; ctr++) {
            Console.WriteLine(gtArgs[ctr].FullName ??
                              "(unassigned) " + gtArgs[ctr].ToString());
          }
         Console.WriteLine();
      }
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:21,代码来源:Type.FullName

输出:

System.Nullable`1
Generic Type Parameters: (unassigned) T

示例5: Display

//引入命名空间
using System;
using System.Reflection;

public class GenericType1<T> 
{
   public void Display(T[] elements)  
   {}
   
   public void HandleT(T obj)
   {}
   
   public bool ChangeValue(ref T arg) 
   {
      return true;
   }
}

public class Example
{
   public static void Main()
   {
      Type t = typeof(GenericType1<>);
      Console.WriteLine("Type Name: {0}", t.FullName);
      MethodInfo[] methods = t.GetMethods(BindingFlags.Instance |
                                          BindingFlags.DeclaredOnly |
                                          BindingFlags.Public);
      foreach (var method in methods) { 
         Console.WriteLine("   Method: {0}", method.Name);
         // Get method parameters.
         ParameterInfo param = method.GetParameters()[0];
         Type paramType = param.ParameterType;
         if (method.Name == "HandleT")
            paramType = paramType.MakePointerType();
         Console.WriteLine("      Parameter: {0}", 
                           paramType.FullName ?? 
                           paramType.ToString() + " (unassigned)");
      }
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:40,代码来源:Type.FullName

输出:

Type Name: GenericType1`1
Method: Display
Parameter: T[] (unassigned))
Method: HandleT
Parameter: T* (unassigned)
Method: ChangeValue
Parameter: T& (unassigned)

示例6: Main

//引入命名空间
using System;
using System.Reflection;

public class Base<T> { }

public class Derived<T> : Base<T> { }

public class Example
{
   public static void Main()
   {
      Type t = typeof(Derived<>);
      Console.WriteLine("Generic Class: {0}", t.FullName);
      Console.WriteLine("   Contains Generic Paramters: {0}",
                        t.ContainsGenericParameters);
      Console.WriteLine("   Generic Type Definition: {0}\n",
                        t.IsGenericTypeDefinition);                 

      Type baseType = t.BaseType;
      Console.WriteLine("Its Base Class: {0}", 
                        baseType.FullName ?? 
                        "(unassigned) " + baseType.ToString());
      Console.WriteLine("   Contains Generic Paramters: {0}",
                        baseType.ContainsGenericParameters);
      Console.WriteLine("   Generic Type Definition: {0}",
                        baseType.IsGenericTypeDefinition);                 
      Console.WriteLine("   Full Name: {0}\n", 
                        baseType.GetGenericTypeDefinition().FullName);

      t = typeof(Base<>);
      Console.WriteLine("Generic Class: {0}", t.FullName);
      Console.WriteLine("   Contains Generic Paramters: {0}",
                        t.ContainsGenericParameters);
      Console.WriteLine("   Generic Type Definition: {0}\n",
                        t.IsGenericTypeDefinition);                 
   }
}
开发者ID:.NET开发者,项目名称:System,代码行数:38,代码来源:Type.FullName

输出:

Generic Class: Derived`1
Contains Generic Paramters: True
Generic Type Definition: True

Its Base Class: (unassigned) Base`1[T]
Contains Generic Paramters: True
Generic Type Definition: False
Full Name: Base`1

Generic Class: Base`1
Contains Generic Paramters: True
Generic Type Definition: True

示例7: Main

//引入命名空间
using System;

class MainClass
{
  static void Main(string[] args)
  {
    Object cls1 = new Object();
    System.String cls2 = "Test String" ;

    Type type1 = cls1.GetType();
    Type type2 = cls2.GetType();

    // Object class output
    Console.WriteLine(type1.BaseType);
    Console.WriteLine(type1.Name);
    Console.WriteLine(type1.FullName);
    Console.WriteLine(type1.Namespace);

    // string output
    Console.WriteLine(type2.BaseType);
    Console.WriteLine(type2.Name);
    Console.WriteLine(type2.FullName);
    Console.WriteLine(type2.Namespace);
  } 
}
开发者ID:C#程序员,项目名称:System,代码行数:26,代码来源:Type.FullName


注:本文中的System.Type.FullName属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。