IsSignUnspecifiedByte 类

定义

指示修饰符既非有符号,也非无符号。Indicates that a modifier is neither signed nor unsigned. 此类不能被继承。This class cannot be inherited.

public ref class IsSignUnspecifiedByte abstract sealed
public static class IsSignUnspecifiedByte
type IsSignUnspecifiedByte = class
Public Class IsSignUnspecifiedByte
继承
IsSignUnspecifiedByte

示例

下面的代码示例使用命名空间中的类创建一个程序集 System.Reflection.Emit ,并将 IsSignUnspecifiedByte 修饰符发送到该程序集。The following code example creates an assembly using classes in the System.Reflection.Emit namespace and emits the IsSignUnspecifiedByte modifier into that assembly.



#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
using namespace System::Runtime::CompilerServices;
using namespace System::Threading;


ref class CodeEmitter
{
private:
    AssemblyBuilder^ asmBuilder;
    String^ asmName;
    ModuleBuilder^ modBuilder;


    void prepareAssembly(String^ name){
        
        // Check the input.
        if(!name){
        
            throw gcnew ArgumentNullException("AssemblyName");
        }

        asmName = name;

        // Create an AssemblyName object and set the name.
        AssemblyName^ asmName = gcnew AssemblyName();

        asmName->Name = name;

        // Use the AppDomain class to create an AssemblyBuilder instance.

        AppDomain^ currentDomain = Thread::GetDomain();

        asmBuilder = currentDomain->DefineDynamicAssembly(asmName,AssemblyBuilderAccess::RunAndSave);

        // Create a dynamic module.
        modBuilder = asmBuilder->DefineDynamicModule(name);
    }


public:

    // Constructor.
    CodeEmitter(String ^ AssemblyName){

        prepareAssembly(AssemblyName);
    }

    // Create a new type.
    TypeBuilder^ CreateType(String^ name){
       
        // Check the input.
        if(!name){
        
            throw gcnew ArgumentNullException("AssemblyName");
        }

        return modBuilder->DefineType( name );
    }

    // Write the assembly.
    void WriteAssembly(MethodBuilder^ entryPoint){
    
        // Check the input.
        if(!entryPoint){
        
            throw gcnew ArgumentNullException("entryPoint");
        }

        asmBuilder->SetEntryPoint( entryPoint );
        asmBuilder->Save( asmName );
    }

};

void main()
{

    // Create a CodeEmitter to handle assembly creation.
    CodeEmitter ^ e = gcnew CodeEmitter("program.exe");

    // Create a new type.
    TypeBuilder^ mainClass = e->CreateType("MainClass");
    
    // Create a new method.
    MethodBuilder^ mBuilder = mainClass->DefineMethod("mainMethod", MethodAttributes::Static);

    // Create an ILGenerator and emit IL for 
    // a simple "Hello World." program.
    ILGenerator^ ilGen = mBuilder->GetILGenerator();

    ilGen->Emit(OpCodes::Ldstr, "Hello World");

    array<Type^>^mType = {String::typeid};

    MethodInfo^ writeMI = Console::typeid->GetMethod( "WriteLine", mType );

    ilGen->EmitCall(OpCodes::Call, writeMI, nullptr );

    ilGen->Emit( OpCodes::Ret );

    /////////////////////////////////////////////////
    /////////////////////////////////////////////////
    // Apply a required custom modifier
    // to a field.
    /////////////////////////////////////////////////
    /////////////////////////////////////////////////

    array<Type^>^fType = {IsSignUnspecifiedByte::typeid};

    mainClass->DefineField("modifiedInteger", Type::GetType("System.Byte"), fType, nullptr, FieldAttributes::Private);

    // Create the type.
    mainClass->CreateType();

    // Write the assembly using a reference to 
    // the entry point.
    e->WriteAssembly(mBuilder);

    Console::WriteLine(L"Assembly created.");
}

注解

某些编程语言(例如 c + +)可识别三个不同的 char 值: signed charunsigned charcharSome programming languages, such as C++, recognize three distinct char values: signed char, unsigned char, and char. 为了将未修改的 char 类型与其他类型区分开来,Microsoft c + + 编译器将 IsSignUnspecifiedByte 修饰符添加到 char 发出到程序集的每个类型。To distinguish the unmodified char type from the others, the Microsoft C++ compiler adds the IsSignUnspecifiedByte modifier to each char type emitted to an assembly.

编译器在元数据中发出自定义修饰符,以更改当默认行为不合适时实时 (JIT) 编译器处理值的方式。Compilers emit custom modifiers within metadata to change the way that the just-in-time (JIT) compiler handles values when the default behavior is not appropriate. 当 JIT 编译器遇到自定义修饰符时,它将按修饰符指定的方式处理值。When the JIT compiler encounters a custom modifier, it handles the value in the way that the modifier specifies. 编译器可以对方法、参数和返回值应用自定义修饰符。Compilers can apply custom modifiers to methods, parameters, and return values. JIT 编译器必须响应所需的修饰符,但可以忽略可选修饰符。The JIT compiler must respond to required modifiers but can ignore optional modifiers.

可以使用以下方法之一将自定义修饰符发送到元数据中:You can emit custom modifiers into metadata using one of the following techniques:

适用于