英語で読む

次の方法で共有


Type.IsAnsiClass プロパティ

定義

AnsiClass に、文字列書式属性として Type が選択されているかどうかを示す値を取得します。

C#
public bool IsAnsiClass { get; }

プロパティ値

trueに、文字列書式属性としてAnsiClass が選択されている場合は Type。それ以外の場合は false

実装

次の例では、フィールド情報を取得し、 属性を AnsiClass 確認します。

C#
using System;
using System.Reflection;
public class MyClass
{
    protected string myField = "A sample protected field." ;
}
public class MyType_IsAnsiClass
{
    public static void Main()
    {
        try
        {
            MyClass myObject = new MyClass();
            // Get the type of the 'MyClass'.
            Type myType = typeof(MyClass);
            // Get the field information and the attributes associated with MyClass.
            FieldInfo myFieldInfo = myType.GetField("myField", BindingFlags.NonPublic|BindingFlags.Instance);
            Console.WriteLine( "\nChecking for the AnsiClass attribute for a field.\n");
            // Get and display the name, field, and the AnsiClass attribute.
            Console.WriteLine("Name of Class: {0} \nValue of Field: {1} \nIsAnsiClass = {2}", myType.FullName, myFieldInfo.GetValue(myObject), myType.IsAnsiClass);
        }
        catch(Exception e)
        {
            Console.WriteLine("Exception: {0}",e.Message);
        }
    }
}

注釈

では StringFormatMask 、文字列形式の属性が選択されます。 文字列書式属性は、文字列の解釈方法を定義することで相互運用性を向上させます。

現在 Type の がジェネリック型を表す場合、このプロパティは、型の構築元のジェネリック型定義に関連します。 たとえば、現在Typeの が (Visual Basic では )MyGenericType(Of Integer) を表すMyGenericType<int>場合、このプロパティの値は によってMyGenericType<T>決定されます。

現在 Type の がジェネリック型の型パラメーターを表す場合、このプロパティは常に を返します false

適用対象

製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.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, 4.8.1
.NET Standard 2.0, 2.1

こちらもご覧ください