Questo articolo è stato tradotto automaticamente. Per visualizzare l'articolo in inglese, selezionare la casella di controllo Inglese. È possibile anche visualizzare il testo inglese in una finestra popup posizionando il puntatore del mouse sopra il testo.
Traduzione
Inglese

Metodo AssemblyBuilder.DefineUnmanagedResource (Byte[])

 

Data di pubblicazione: novembre 2016

Definisce una risorsa non gestita per questo assembly come BLOB opaco di byte.

Spazio dei nomi:   System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

public void DefineUnmanagedResource(
	byte[] resource
)

Parametri

resource
Type: System.Byte[]

BLOB opaco di byte che rappresenta la risorsa non gestita.

Exception Condition
ArgumentException

Una risorsa non gestita è stata definita in precedenza.

ArgumentNullException

resource è null.

SecurityException

Il chiamante non dispone dell'autorizzazione richiesta.

An assembly can be associated with only one unmanaged resource. This means that calling M:System.Reflection.Emit.AssemblyBuilder.DefineVersionInfoResource(System.String,System.String,System.String,System.String,System.String) or M:System.Reflection.Emit.AssemblyBuilder.DefineUnmanagedResource(System.Byte[]) after either one of the methods was called previously will throw the System.ArgumentException being throw. Multiple unmanaged resources need to be merged with a tool such as the Microsoft ResMerge utility (not supplied with the common language runtime).

The following code sample creates and attaches an array of bytes representing an unmanaged resource to a dynamic assembly, using DefineUnmanagedResource.

using System;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;

public class MyAssemblyResource
{
   internal static void Main()
   {
      AssemblyBuilder myAssembly = CreateAssembly("MyEmitTestAssembly");

      // Defines a standalone managed resource for this assembly.
      IResourceWriter myResourceWriter = myAssembly.DefineResource("myResourceFile",
         "A sample Resource File", "MyAssemblyResource.resources", 
         ResourceAttributes.Private);

      myResourceWriter.AddResource("AddResource Test", "Testing for the added resource");

      myAssembly.Save(myAssembly.GetName().Name + ".dll");

      // Defines an unmanaged resource file for this assembly.
      myAssembly.DefineUnmanagedResource(new byte[]{01, 00, 01});
   }

   private static AssemblyBuilder CreateAssembly(string name)
   {
      AssemblyName aName = new AssemblyName(name);
      AssemblyBuilder myAssembly = 
         AppDomain.CurrentDomain.DefineDynamicAssembly(aName,
            AssemblyBuilderAccess.Save);

      // Define a dynamic module.
      ModuleBuilder myModule = 
         myAssembly.DefineDynamicModule(aName.Name, aName.Name + ".dll");

      // Define a public class named "EmitClass" in the assembly.
      TypeBuilder myEmitClass = myModule.DefineType("EmitClass", TypeAttributes.Public);

      // Define the Display method.
      MethodBuilder myMethod = myEmitClass.DefineMethod("Display",
         MethodAttributes.Public, typeof(String), null);

      // Generate IL for Display method.
      ILGenerator methodIL = myMethod.GetILGenerator();
      methodIL.Emit(OpCodes.Ldstr, "Display method gets called.");
      methodIL.Emit(OpCodes.Ret);

      myEmitClass.CreateType();

      return(myAssembly);
   }
}

ReflectionPermission

when invoked late-bound through mechanisms such as M:System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[]). Associated enumeration: F:System.Security.Permissions.ReflectionPermissionFlag.MemberAccess.

.NET Framework
Disponibile da 1.1
Torna all'inizio
Mostra: