|
Dieser Artikel wurde maschinell übersetzt. Bewegen Sie den Mauszeiger über die Sätze im Artikel, um den Originaltext anzuzeigen. Weitere Informationen
|
Übersetzung
Original
|
FieldBuilder-Klasse
System.Reflection.MemberInfo
System.Reflection.FieldInfo
System.Reflection.Emit.FieldBuilder
Namespace: System.Reflection.Emit
Assembly: mscorlib (in mscorlib.dll)
Der FieldBuilder-Typ macht die folgenden Member verfügbar.
| Name | Beschreibung | |
|---|---|---|
![]() | Attributes | |
![]() | CustomAttributes | |
![]() | DeclaringType | |
![]() | FieldHandle | |
![]() | FieldType | |
![]() | IsAssembly | |
![]() | IsFamily | |
![]() | IsFamilyAndAssembly | |
![]() | IsFamilyOrAssembly | |
![]() | IsInitOnly | |
![]() | IsLiteral | |
![]() | IsNotSerialized | |
![]() | IsPinvokeImpl | |
![]() | IsPrivate | |
![]() | IsPublic | |
![]() | IsSecurityCritical | |
![]() | IsSecuritySafeCritical | |
![]() | IsSecurityTransparent | |
![]() | IsSpecialName | |
![]() | IsStatic | |
![]() | MemberType | |
![]() | MetadataToken | |
![]() | Module | |
![]() | Name | |
![]() | ReflectedType |
| Name | Beschreibung | |
|---|---|---|
![]() | Equals | |
![]() | GetCustomAttributes(Boolean) | |
![]() | GetCustomAttributes(Type, Boolean) | |
![]() | GetCustomAttributesData | |
![]() | GetHashCode | |
![]() | GetOptionalCustomModifiers | |
![]() | GetRawConstantValue | |
![]() | GetRequiredCustomModifiers | |
![]() | GetToken | |
![]() | GetType | |
![]() | GetValue | |
![]() | GetValueDirect | |
![]() | IsDefined | |
![]() | SetConstant | |
![]() | SetCustomAttribute(CustomAttributeBuilder) | |
![]() | SetCustomAttribute(ConstructorInfo, Byte[]) | |
![]() | SetMarshal | Veraltet. |
![]() | SetOffset | |
![]() | SetValue(Object, Object) | |
![]() | SetValue(Object, Object, BindingFlags, Binder, CultureInfo) | |
![]() | SetValueDirect | |
![]() | ToString |
| Name | Beschreibung | |
|---|---|---|
![]() | GetCustomAttribute(Type) | Überladen. |
![]() | GetCustomAttribute(Type, Boolean) | Überladen. |
![]() | GetCustomAttribute<T>() | Überladen. |
![]() | GetCustomAttribute<T>(Boolean) | Überladen. |
![]() | GetCustomAttributes() | Überladen. |
![]() | GetCustomAttributes(Type) | Überladen. |
![]() | GetCustomAttributes<T>() | Überladen. |
![]() | GetCustomAttributes<T>(Boolean) | Überladen. |
![]() | IsDefined |
| Name | Beschreibung | |
|---|---|---|
![]() ![]() | _FieldBuilder.GetIDsOfNames | |
![]() ![]() | _FieldBuilder.GetTypeInfo | |
![]() ![]() | _FieldBuilder.GetTypeInfoCount | |
![]() ![]() | _FieldBuilder.Invoke | |
![]() ![]() | _FieldInfo.GetIDsOfNames | |
![]() ![]() | _FieldInfo.GetType | |
![]() ![]() | _FieldInfo.GetTypeInfo | |
![]() ![]() | _FieldInfo.GetTypeInfoCount | |
![]() ![]() | _FieldInfo.Invoke | |
![]() ![]() | _MemberInfo.GetIDsOfNames | |
![]() ![]() | _MemberInfo.GetType | |
![]() ![]() | _MemberInfo.GetTypeInfo | |
![]() ![]() | _MemberInfo.GetTypeInfoCount | |
![]() ![]() | _MemberInfo.Invoke |
Hinweis |
|---|
Hinweis |
|---|
Das auf diesen Typ oder Member angewendete HostProtectionAttribute-Attribut besitzt den folgenden Resources-Eigenschaftswert: MayLeakOnAbort. Das HostProtectionAttribute hat keine Auswirkungen auf Desktopanwendungen (die normalerweise durch Doppelklicken auf ein Symbol, Eingeben eines Befehls oder einer URL in einem Browser gestartet werden). Weitere Informationen finden Sie unter der HostProtectionAttribute-Klasse oder unter SQL Server-Programmierung und Hostschutzattribute. |
using System; using System.Threading; using System.Reflection; using System.Reflection.Emit; using System.Security.Permissions; public class FieldBuilder_Sample { private static Type CreateType(AppDomain currentDomain) { // Create an assembly. AssemblyName myAssemblyName = new AssemblyName(); myAssemblyName.Name = "DynamicAssembly"; AssemblyBuilder myAssembly = currentDomain.DefineDynamicAssembly(myAssemblyName,AssemblyBuilderAccess.Run); // Create a dynamic module in Dynamic Assembly. ModuleBuilder myModuleBuilder=myAssembly.DefineDynamicModule("MyModule"); // Define a public class named "MyClass" in the assembly. TypeBuilder myTypeBuilder= myModuleBuilder.DefineType("MyClass",TypeAttributes.Public); // Define a private String field named "MyField" in the type. FieldBuilder myFieldBuilder= myTypeBuilder.DefineField("MyField", typeof(string),FieldAttributes.Private|FieldAttributes.Static); // Create the constructor. Type[] constructorArgs = { typeof(String) }; ConstructorBuilder constructor = myTypeBuilder.DefineConstructor( MethodAttributes.Public, CallingConventions.Standard, constructorArgs); ILGenerator constructorIL = constructor.GetILGenerator(); constructorIL.Emit(OpCodes.Ldarg_0); ConstructorInfo superConstructor = typeof(Object).GetConstructor(new Type[0]); constructorIL.Emit(OpCodes.Call, superConstructor); constructorIL.Emit(OpCodes.Ldarg_0); constructorIL.Emit(OpCodes.Ldarg_1); constructorIL.Emit(OpCodes.Stfld, myFieldBuilder); constructorIL.Emit(OpCodes.Ret); // Create the MyMethod method. MethodBuilder myMethodBuilder= myTypeBuilder.DefineMethod("MyMethod", MethodAttributes.Public,typeof(String),null); ILGenerator methodIL = myMethodBuilder.GetILGenerator(); methodIL.Emit(OpCodes.Ldarg_0); methodIL.Emit(OpCodes.Ldfld, myFieldBuilder); methodIL.Emit(OpCodes.Ret); Console.WriteLine("Name :"+myFieldBuilder.Name); Console.WriteLine("DeclaringType :"+myFieldBuilder.DeclaringType); Console.WriteLine("Type :"+myFieldBuilder.FieldType); Console.WriteLine("Token :"+myFieldBuilder.GetToken().Token); return myTypeBuilder.CreateType(); } [PermissionSetAttribute(SecurityAction.Demand, Name="FullTrust")] public static void Main() { try { Type myType = CreateType(Thread.GetDomain()); // Create an instance of the "HelloWorld" class. Object helloWorld = Activator.CreateInstance(myType, new Object[] { "HelloWorld" }); // Invoke the "MyMethod" method of the "MyClass" class. Object myObject = myType.InvokeMember("MyMethod", BindingFlags.InvokeMethod, null, helloWorld, null); Console.WriteLine("MyClass.MyMethod returned: \"" + myObject + "\""); } catch( Exception e) { Console.WriteLine("Exception Caught "+e.Message); } } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core-Rolle wird nicht unterstützt), Windows Server 2008 R2 (Server Core-Rolle wird mit SP1 oder höher unterstützt; Itanium wird nicht unterstützt)
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.
