Type に、文字列書式属性として AnsiClass が選択されているかどうかを示す値を取得します。
Public ReadOnly Property IsAnsiClass As Boolean
[C#]
public bool IsAnsiClass {get;}
[C++]
public: __property bool get_IsAnsiClass();
[JScript]
public function get IsAnsiClass() : Boolean;
プロパティ値
Type に、文字列書式属性として AnsiClass が選択されている場合は true 。それ以外の場合は false 。
解説
StringFormatMask は、文字列書式属性を選択します。文字書式属性は、文字列の解釈方法を定義することによって、相互運用性を拡張します。
使用例
[Visual Basic, C#, C++] フィールド情報を取得し、 AnsiClass 属性のチェックを行う例を次に示します。
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class MyClass1
Protected myField As String = "A sample protected field."
End Class 'MyClass1
Public Class MyType_IsAnsiClass
Public Shared Sub Main()
Try
Dim myObject As New MyClass1()
' Get the type of MyClass1.
Dim myType As Type = GetType(MyClass1)
' Get the field information and the attributes associated with MyClass1.
Dim myFieldInfo As FieldInfo = myType.GetField("myField", BindingFlags.NonPublic Or BindingFlags.Instance)
Console.WriteLine(ControlChars.NewLine + "Checking for AnsiClass attribute for a field." + ControlChars.NewLine)
' Get and display the name, field, and the AnsiClass attribute.
Console.WriteLine("Name of Class: {0} " + ControlChars.NewLine + "Value of Field: {1} " + ControlChars.NewLine + "IsAnsiClass = {2}", myType.FullName, myFieldInfo.GetValue(myObject), myType.IsAnsiClass)
Catch e As Exception
Console.WriteLine("Exception: {0}", e.Message.ToString())
End Try
End Sub 'Main
End Class 'MyType_IsAnsiClass
[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);
}
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;
public __gc class MyClass {
protected:
String* myField;
public:
MyClass() {
myField = "A sample protected field";
}
};
int 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(S"myField", static_cast<BindingFlags>(BindingFlags::NonPublic|BindingFlags::Instance));
Console::WriteLine(S"\nChecking for the AnsiClass attribute for a field.\n");
// Get and display the name, field, and the AnsiClass attribute.
Console::WriteLine(S"Name of Class: {0} \nValue of Field: {1} \nIsAnsiClass = {2}", myType->FullName, myFieldInfo->GetValue(myObject),__box( myType->IsAnsiClass));
} catch (Exception* e) {
Console::WriteLine(S"Exception: {0}", e->Message);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
Type クラス | Type メンバ | System 名前空間 | TypeAttributes | IsUnicodeClass | IsAutoClass