Freigeben über


Type.IsAnsiClass-Eigenschaft

Ruft einen Wert ab, der angibt, ob für Type das Zeichenfolgenformatattribut AnsiClass ausgewählt ist.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public ReadOnly Property IsAnsiClass As Boolean
'Usage
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

Eigenschaftenwert

true, wenn für Type das Zeichenfolgenformatattribut AnsiClass ausgewählt ist, andernfalls false.

Hinweise

Die Zeichenfolgenformatattribute werden mit StringFormatMask ausgewählt. Die Zeichenfolgenformatattribute verbessern die Interoperabilität, indem sie definieren, wie Zeichenfolgen interpretiert werden sollen.

Wenn der aktuelle Type einen generischen Typ darstellt, gilt diese Eigenschaft für die generische Typdefinition, aus der der Typ konstruiert wurde. Wenn z. B. der aktuelle TypeMyGenericType<int> darstellt (MyGenericType(Of Integer) in Visual Basic), wird der Wert dieser Eigenschaft durch MyGenericType<T> bestimmt.

Wenn der aktuelle Type einen Typparameter eines generischen Typs darstellt, gibt diese Eigenschaft immer false zurück.

Beispiel

Im folgenden Beispiel werden die Feldinformationen abgerufen und das AnsiClass-Attribut überprüft.

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

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

Type-Klasse
Type-Member
System-Namespace
TypeAttributes
IsUnicodeClass
IsAutoClass