Type.IsAnsiClass 属性
获取一个指示是否为 Type 选择了字符串格式属性 (Attribute) AnsiClass 的值。
**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public ReadOnly Property IsAnsiClass As Boolean
用法
Dim instance As Type
Dim value As Boolean
value = instance.IsAnsiClass
public bool IsAnsiClass { get; }
public:
virtual property bool IsAnsiClass {
bool get () sealed;
}
/** @property */
public final boolean get_IsAnsiClass ()
public final function get IsAnsiClass () : boolean
属性值
如果为 Type 选择了字符串格式属性 (Attribute)AnsiClass,则为 true;否则为 false。
备注
StringFormatMask 选择字符串格式属性。字符串格式属性通过定义字符串的解释方式来增强交互操作。
如果当前 Type 表示某个泛型类型,则此属性 (Property) 适用于在其基础上构造该类型的泛型类型定义。例如,如果当前 Type 表示 MyGenericType<int>
(在 Visual Basic 中为 MyGenericType(Of Integer)
),则此属性的值由 MyGenericType<T>
确定。
如果当前 Type 表示泛型类型的类型形参,则此属性 (Property) 始终返回 false。
示例
下面的示例获取字段信息,并检查 AnsiClass 属性 (Attribute)。
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
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);
}
}
}
using namespace System;
using namespace System::Reflection;
public ref class MyClass
{
protected:
String^ myField;
public:
MyClass()
{
myField = "A sample protected field";
}
};
int main()
{
try
{
MyClass^ myObject = gcnew MyClass;
// Get the type of the 'MyClass'.
Type^ myType = MyClass::typeid;
// Get the field information and the attributes associated with MyClass.
FieldInfo^ myFieldInfo = myType->GetField( "myField", static_cast<BindingFlags>(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 );
}
}
import System.*;
import System.Reflection.*;
public class MyClass
{
protected String myField = "A sample protected field.";
} //MyClass
public class MyType_IsAnsiClass
{
public static void main(String[] args)
{
try {
MyClass myObject = new MyClass();
// Get the type of the 'MyClass'.
Type myType = MyClass.class.ToType();
// 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} \n"
+ "IsAnsiClass = {2}", myType.get_FullName(), myFieldInfo.
GetValue(myObject), System.Convert.ToString(myType.
get_IsAnsiClass()));
}
catch (System.Exception e) {
Console.WriteLine("Exception: {0}", e.get_Message());
}
} //main
} //MyType_IsAnsiClass
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
Type 类
Type 成员
System 命名空间
TypeAttributes
IsUnicodeClass
IsAutoClass