英語で読む

次の方法で共有


Type.FullName プロパティ

定義

型の完全修飾名を取得します。その名前空間を含みますが、アセンブリは含みません。

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

プロパティ値

String

型の完全修飾名で、名前空間を含むが、アセンブリは含まないもの。現在のインスタンスが、ジェネリック型パラメーター、配列型、ポインター型、または型パラメーターに基づくnull 型、またはジェネリック型定義ではないが未解決の型パラメーターを含むジェネリック型を表す場合は、byref

実装

次の例では、指定した型の完全な名前を表示します。

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.
 */

次の例では、 メソッドによって返される文字列と、および ToString Name FullName の各プロパティを比較 AssemblyQualifiedName します。

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

注釈

たとえば、型の完全修飾名は String です System.String 。 これを、 プロパティによって返されるアセンブリ修飾名と対比します。この名前は、完全な名前と完全なアセンブリ名 AssemblyQualifiedName で構成されます。

現在の型が閉じたジェネリック型を表している場合、 プロパティによって返される文字列内の型引数は、ジェネリック型自体の文字列表現が完全なアセンブリ名で修飾されていない場合でも、完全なアセンブリ名で修飾されます。 FullName 次の例は、ジェネリック型の定義を表す型と、閉じたジェネリック型を表す型の FullName プロパティの違いを示しています。

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]]

このプロパティは、次の場合に null を返します。

  • 現在の Type オブジェクトは、ジェネリック型の型パラメーターを表します。

    次の例では、 型の型パラメーターを取得し、その プロパティ Nullable<T> の表示を試 FullName みています。

    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
    
  • 現在の Type オブジェクトは、配列型、ポインター型、またはジェネリック型パラメーターに基づく byref 型を表します。

    次の例では、 という 3 つのメソッドを持つジェネリック型を定義します。このメソッドには、T 型の配列が渡されます。この配列には T オブジェクトが渡され、 は参照渡しで Generictype1<T> Display(T[]) HandleT(T) ChangeValue(ref T) T オブジェクトが渡されます。 C# と Visual Basic では、メソッド内のポインターとして T を定義することはできません。そのため、ジェネリック型へのポインターを作成するには、メソッドのパラメーター型を表す オブジェクトで メソッドを呼び出す必要があります。 HandleT MakePointerType Type この例の出力は、3 つのケースすべてで プロパティが FullName であるという結果を示しています null

    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)
    
  • 現在の型には、特定の型に置き換えされていないジェネリック型パラメーター (つまり、プロパティが を返します) が含まれていますが、その型はジェネリック型定義ではありません (つまり、プロパティは ContainsGenericParameters true を返 IsGenericTypeDefinition します)。 false

    次の例では、 Derived<T> は から継承します Base<T> 。 プロパティは の基本型を表す オブジェクトを取得し、その BaseType Type Derived<T> FullName プロパティは を返します null

    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
    

    ではない を取得するには、 メソッドを使用して、例に示すようにジェネリック型 FullName null GetGenericTypeDefinition の定義を取得します。

このプロパティは読み取り専用です。

適用対象

製品 バージョン
.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

こちらもご覧ください