Type.FullName Özellik

Tanım

Ad alanı dahil olmak üzere türün tam adını alır, ancak derlemesini alır.

C#
public abstract string FullName { get; }
C#
public abstract string? FullName { get; }

Özellik Değeri

String

Ad alanı dahil ancak derlemesi dahil olmak üzere türün tam adı; ya da geçerli örnek genel bir tür parametresini, bir dizi türünü, işaretçi türünü veya tür parametresini temel alan bir türü ya da genel tür tanımı olmayan ancak çözümlenmemiş tür parametreleri içeren genel bir türü temsil null byref ediyorsa.

Uygulamalar

Örnekler

Aşağıdaki örnekte belirtilen türün tam adı görüntülenir.

C#
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);
    }
}

/* This example produces the following output:

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

Aşağıdaki örnek, yöntemi tarafından döndürülen dizeleri ToString ve , ve özelliklerini Name FullName AssemblyQualifiedName karşılar.

C#
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();
    }
}
// The example displays output like the following:
//    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

Açıklamalar

Örneğin, türünün tam adı String System.String olur. Bunu, tam adı ve tam derleme adını oluşan özelliği tarafından AssemblyQualifiedName döndürülen derleme tam adı ile karşılaştırın.

Geçerli tür kapalı bir genel türü temsil ediyorsa, özelliği tarafından döndürülen dizede tür bağımsız değişkenleri, genel türün dize gösterimi tam derleme adıyla tam olarak uygun değildir. FullName Aşağıdaki örnek, genel tür tanımını temsil eden bir türün FullName özelliğiyle kapalı bir genel türü temsil eden arasındaki farkı gösterir.

C#
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);
   }
}
// The example displays the following output:
// System.Collections.Generic.List`1
//
// System.Collections.Generic.List`1[[System.String, mscorlib,
//        Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

Bu özellik şu durumda null döndürür:

  • Geçerli Type nesne, genel türe göre bir tür parametresini temsil eder.

    Aşağıdaki örnek, türün tür parametresini Nullable<T> almakta ve özelliğini görüntülemeye FullName çalışır.

    C#
    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();
          }
       }
    }
    // The example displays the following output:
    //       System.Nullable`1
    //          Generic Type Parameters: (unassigned) T
    
  • Geçerli nesne bir dizi türünü, işaretçi türünü veya genel tür Type byref parametresini temel alan bir türü temsil eder.

    Aşağıdaki örnek, üç yöntem içeren genel bir türü tanımlar: T türünde bir diziye geçirildi; bu bir T nesnesine geçirildi; ve bu da başvuruyla Generictype1<T> Display(T[]) bir T HandleT(T) ChangeValue(ref T) nesnesine geçirildi. C# Visual Basic T'yi yönteminde işaretçi olarak tanımlamamıza izin vermey olduğundan, genel bir türe işaretçi oluşturmak için yöntemin parametre türünü temsil eden nesnesinde yöntemini HandleT MakePointerType Type çağırmamız gerekir. Örnekteki çıktı, üç durumda da özelliğinin FullName olduğunu null gösterir.

    C#
    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)");
          }
       }
    }
    // The example displays the following output:
    //       Type Name: GenericType1`1
    //          Method: Display
    //             Parameter: T[] (unassigned))
    //          Method: HandleT
    //             Parameter: T* (unassigned)
    //          Method: ChangeValue
    //             Parameter: T& (unassigned)
    
  • Geçerli tür, belirli türler tarafından değiştiriLn olmayan genel tür parametrelerini içerir (yani özelliği döndürür), ancak tür genel bir tür tanımı değildir ContainsGenericParameters true (yani IsGenericTypeDefinition özellik döndürür false

    Aşağıdaki örnekte, 'den Derived<T> Base<T> devralıyor. özelliği, BaseType temel Type türünü temsil eden nesneyi elde eder Derived<T> ve özelliği FullName null döndürür.

    C#
    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);                 
       }
    }
    // The example displays the following output:
    //       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
    

    olmayan bir FullName almak null için, örnekte gösterildiği GetGenericTypeDefinition gibi genel tür tanımını almak için yöntemini kullanabilirsiniz.

Bu özellik salt okunur durumdadır.

Şunlara uygulanır

Ürün Sürümler
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Ayrıca bkz.