Skip to main content

parse_method_spec_signature

Function parse_method_spec_signature 

pub fn parse_method_spec_signature(data: &[u8]) -> Result<SignatureMethodSpec>
Expand description

Parse a method specification signature from binary signature data.

Parses .NET method specification signatures that provide type arguments for generic method instantiations. Method specifications are used when calling generic methods with specific type arguments, enabling the runtime to create specialized method implementations.

§Method Specification Format

Method specifications provide type arguments for generic method calls:

[METHODSPEC] [GenericArgCount] [TypeArg1] [TypeArg2] ...

§Generic Method Instantiation

  • Generic Methods: Method<T>(T item) becomes Method<int>(int item)
  • Multiple Type Args: Method<T,U>(T first, U second)
  • Nested Generics: Method<List<T>>(List<T> items)
  • Constrained Types: Type arguments satisfying method constraints

§Examples

use dotscope::metadata::signatures::{parse_method_spec_signature, TypeSignature};

// Parse "Method<int>" - single type argument
let signature = parse_method_spec_signature(&[
    0x0A, // METHODSPEC marker
    0x01, // 1 type argument
    0x08, // I4 (int) type argument
])?;

assert_eq!(signature.generic_args.len(), 1);
assert_eq!(signature.generic_args[0], TypeSignature::I4);

// Parse "Method<int, string>" - multiple type arguments
let signature = parse_method_spec_signature(&[
    0x0A, // METHODSPEC marker
    0x02, // 2 type arguments
    0x08, // I4 (int) first type argument
    0x0E, // String second type argument
])?;

assert_eq!(signature.generic_args.len(), 2);
assert_eq!(signature.generic_args[0], TypeSignature::I4);
assert_eq!(signature.generic_args[1], TypeSignature::String);

§Parameters

  • data: Binary signature data from a .NET assembly’s blob heap

§Returns

A crate::metadata::signatures::SignatureMethodSpec containing:

  • Array of type arguments for generic method instantiation
  • Type information for runtime method specialization
  • Generic constraint validation data

§Errors

Returns crate::Error if:

  • Signature data is malformed or doesn’t start with method spec marker
  • Invalid type argument count or type encoding
  • Unknown element types in type arguments
  • Recursive type references exceed maximum depth

§Runtime Behavior

Method specifications enable the runtime to:

  • Create Specialized Methods: Generate type-specific IL code
  • Validate Constraints: Ensure type arguments satisfy generic constraints
  • Optimize Performance: Enable type-specific optimizations
  • Support Reflection: Provide complete type information for introspection