Bagikan melalui


BlobEncoder.MethodSignature Metode

Definisi

Mengodekan blob tanda tangan metode.

public System.Reflection.Metadata.Ecma335.MethodSignatureEncoder MethodSignature (System.Reflection.Metadata.SignatureCallingConvention convention = System.Reflection.Metadata.SignatureCallingConvention.Default, int genericParameterCount = 0, bool isInstanceMethod = false);
member this.MethodSignature : System.Reflection.Metadata.SignatureCallingConvention * int * bool -> System.Reflection.Metadata.Ecma335.MethodSignatureEncoder
Public Function MethodSignature (Optional convention As SignatureCallingConvention = System.Reflection.Metadata.SignatureCallingConvention.Default, Optional genericParameterCount As Integer = 0, Optional isInstanceMethod As Boolean = false) As MethodSignatureEncoder

Parameter

convention
SignatureCallingConvention

Konvensi panggilan.

genericParameterCount
Int32

Jumlah parameter generik.

isInstanceMethod
Boolean

true untuk mengodekan tanda tangan metode instans, false untuk mengodekan tanda tangan metode statis.

Mengembalikan

Encoder tanda tangan lainnya termasuk nilai dan parameter yang dikembalikan.

Pengecualian

genericParameterCount tidak dalam rentang [0, 0xffff].

Contoh

Contoh ini menunjukkan cara mengodekan tanda tangan metode yang berbeda:

static BlobBuilder EncodeMethodSignatureParameterless()
{
    // void Method()
    var methodSignature = new BlobBuilder();

    new BlobEncoder(methodSignature).
        MethodSignature().
        Parameters(0, returnType => returnType.Void(), parameters => { });
    
    return methodSignature;
}

static BlobBuilder EncodeMethodSignaturePrimitiveTypes()
{
    // double Method(double x, double y)
    var methodSignature = new BlobBuilder();

    new BlobEncoder(methodSignature).
        MethodSignature().
        Parameters(2, returnType => returnType.Type().Double(),
        parameters => {
            parameters.AddParameter().Type().Double();
            parameters.AddParameter().Type().Double();
        });

    return methodSignature;
}

static BlobBuilder EncodeMethodSignatureClassType(MetadataBuilder metadataBuilder)
{
    // void Method(System.Threading.Thread x)
    var methodSignature = new BlobBuilder();
    
    AssemblyReferenceHandle mscorlibAssemblyRef = metadataBuilder.AddAssemblyReference(
        name: metadataBuilder.GetOrAddString("System.Threading.Thread"),
        version: new Version(4, 0, 0, 0),
        culture: default(StringHandle),
        publicKeyOrToken: default(BlobHandle),
        flags: default(AssemblyFlags),
        hashValue: default(BlobHandle));

    TypeReferenceHandle typeRef = metadataBuilder.AddTypeReference(
        mscorlibAssemblyRef,
        metadataBuilder.GetOrAddString("System.Threading"),
        metadataBuilder.GetOrAddString("Thread"));

    new BlobEncoder(methodSignature).
        MethodSignature().
        Parameters(1, returnType => returnType.Void(),
        parameters => {
            parameters.AddParameter().Type().Type(typeRef, false);
        });

    return methodSignature;
}

static BlobBuilder EncodeMethodSignatureModifiedTypes()
{
    // void Method(ref int x, int[] y)
    var methodSignature = new BlobBuilder();

    new BlobEncoder(methodSignature).
        MethodSignature().
        Parameters(2, returnType => returnType.Void(),
        parameters => {
            parameters.AddParameter().Type(isByRef: true).Int32();
            parameters.AddParameter().Type().SZArray().Int32();
        });

    return methodSignature;
}

public static BlobBuilder EncodeMethodSignatureGeneric()
{
    // void Method<T>(T x)
    var methodSignature = new BlobBuilder();

    new BlobEncoder(methodSignature).
        MethodSignature(genericParameterCount: 1).
        Parameters(1, returnType => returnType.Void(),
        parameters => {
            parameters.AddParameter().Type().GenericMethodTypeParameter(0);
        });

    return methodSignature;
}

Keterangan

Blob tanda tangan metode digunakan saat mendefinisikan atau mereferensikan metode dalam metadata .NET. Untuk contoh lengkap memancarkan definisi metode, lihat MetadataBuilder keterangan kelas.

Berlaku untuk