Skip to main content

SignatureParameter

Struct SignatureParameter 

pub struct SignatureParameter {
    pub modifiers: CustomModifiers,
    pub by_ref: bool,
    pub base: TypeSignature,
}
Expand description

Method parameter signature with modifiers and reference semantics.

Represents a single parameter or return type in method signatures, property signatures, and other callable member definitions. Includes support for custom modifiers, by-reference semantics, and all .NET parameter types.

§Parameter Categories

§Value Parameters

Standard pass-by-value semantics where the parameter receives a copy:

public void Method(int value)           // Value parameter
public void Method(string text)         // Reference type, but passed by value

§Reference Parameters

Pass-by-reference semantics using ref, out, or in keywords:

public void Method(ref int value)       // Bidirectional reference
public void Method(out int result)      // Output-only reference  
public void Method(in DateTime time)    // Read-only reference

§Return Types

Method return types use the same parameter structure:

public int GetValue()                   // Value return
public ref int GetReference()           // Reference return

§Custom Modifiers for Parameters

Parameters can have custom modifiers for advanced scenarios:

§Common Parameter Modifiers

  • Calling Conventions: Platform-specific parameter passing
  • Marshalling Hints: Interop type conversion guidance
  • Optimization Annotations: Compiler optimization hints
  • Security Metadata: Parameter validation requirements

§Example Modifier Uses

// These might generate custom modifiers:
[MarshalAs(UnmanagedType.LPStr)]
public void Method(string text);        // Marshalling modifier

[In, Out]
public void Method(ref byte[] buffer);  // Directional modifiers

§Binary Format (ECMA-335)

Parameters are encoded as:

[CustomMod*] [BYREF] <type>

Where:

  • [CustomMod*]: Optional custom modifier sequence
  • [BYREF]: Optional reference semantics marker (0x10)
  • <type>: Parameter type signature

§Reference Semantics Details

§ref Parameters (by_ref = true)

  • Initialization: Must be initialized before passing
  • Direction: Input and output
  • Null Safety: Cannot pass null references
  • Lifetime: Reference must not outlive the referenced object

§out Parameters (by_ref = true with attribute)

  • Initialization: Does not need to be initialized before passing
  • Direction: Output only
  • Assignment: Must be assigned before method returns
  • Compiler Checking: Definite assignment analysis

§in Parameters (by_ref = true with attribute)

  • Read-Only: Cannot modify the referenced value
  • Performance: Avoids copying large value types
  • Safety: Compiler prevents modification
  • Implicit: Can be called with value arguments

§Examples

§Simple Value Parameter

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

let int_param = SignatureParameter {
    modifiers: vec![],                    // No custom modifiers
    by_ref: false,                        // Pass by value
    base: TypeSignature::I4,             // int parameter
};

§Reference Parameter

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

let ref_param = SignatureParameter {
    modifiers: vec![],
    by_ref: true,                         // Pass by reference
    base: TypeSignature::String,         // ref string parameter
};

§Parameter with Custom Modifiers

use dotscope::metadata::signatures::{CustomModifier, SignatureParameter, TypeSignature};
use dotscope::metadata::token::Token;

let marshalled_param = SignatureParameter {
    modifiers: vec![
        CustomModifier {
            is_required: false,
            modifier_type: Token::new(0x02000001),  // Marshalling modifier
        },
    ],
    by_ref: false,
    base: TypeSignature::String,         // String with marshalling info
};

§Complex Return Type

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

// Return type: ref List<int>
let return_type = SignatureParameter {
    modifiers: vec![],
    by_ref: true,                         // Reference return
    base: TypeSignature::GenericInst(
        Box::new(TypeSignature::Class(dotscope::metadata::token::Token::new(0x02000001))), // List<T>
        vec![TypeSignature::I4],          // Type argument: int
    ),
};

§Compatibility Rules

Parameter compatibility follows .NET type system rules:

  • Exact Matches: Always compatible
  • Inheritance: Derived types compatible with base parameter types
  • Interfaces: Implementing types compatible with interface parameters
  • Generics: Type arguments must satisfy constraints
  • References: Reference types must match exactly

§ECMA-335 Compliance

This structure implements ECMA-335 Partition II, Section 23.2.10 (Parameter signature) and supports all standard parameter scenarios defined in the specification.

§See Also

Fields§

§modifiers: CustomModifiers

Custom modifiers that apply to this parameter.

A collection of custom modifiers specifying additional constraints or annotations for the parameter. Most parameters have no custom modifiers (empty vector).

Each modifier can be either required (modreq) or optional (modopt):

  • Required Modifiers: Must be understood for type compatibility
  • Optional Modifiers: Can be safely ignored if not recognized

§Modifier Types

  • Marshalling: How to convert between managed and native types (modopt(In), modopt(Out))
  • Validation: Parameter validation requirements (modreq(NotNull))
  • Optimization: Hints for compiler optimizations
  • Platform: OS or architecture-specific constraints

§Common Scenarios

  • P/Invoke parameter marshalling specifications
  • COM interop calling convention requirements
  • Security annotations for parameter validation
  • Tool-specific metadata for static analysis
§by_ref: bool

Whether this parameter uses reference semantics.

When true, indicates that the parameter is passed by reference using ref, out, or in keywords in C#. The exact semantics are typically specified through attributes or calling context.

§Reference Semantics

  • Performance: Avoids copying large value types
  • Aliasing: Parameter becomes an alias to the original variable
  • Lifetime: Reference must not outlive the referenced object
  • Safety: Managed references are GC-safe, unlike pointers

§Usage Patterns

  • ref: Bidirectional parameter modification
  • out: Output parameter that must be assigned
  • in: Read-only reference for performance
  • Return values: Reference returns for efficient access
§base: TypeSignature

The type of this parameter or return value.

Can be any valid .NET type including:

  • Primitives: int, double, bool, char
  • Objects: string, object, custom classes
  • Value Types: DateTime, Guid, custom structs
  • Generics: List<T>, Dictionary<K,V>, type parameters
  • Arrays: int[], string[,], jagged arrays
  • Special Types: void (return only), TypedByRef

§Type Constraints

The type must be valid for the parameter context:

  • Return types can be void
  • Reference parameters have additional lifetime constraints
  • Generic parameters must satisfy type constraints
  • Pointer types require unsafe context

Trait Implementations§

§

impl Clone for SignatureParameter

§

fn clone(&self) -> SignatureParameter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for SignatureParameter

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Default for SignatureParameter

§

fn default() -> SignatureParameter

Returns the “default value” for a type. Read more
§

impl Display for SignatureParameter

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl PartialEq for SignatureParameter

§

fn eq(&self, other: &SignatureParameter) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl StructuralPartialEq for SignatureParameter

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source§

fn type_name(&self) -> &'static str

Gets the type name of self
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: AsAny + ?Sized,

Source§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
Source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, A> IntoAst<A> for T
where T: Into<A>, A: Ast,

Source§

fn into_ast(self, _a: &A) -> A

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> TryClone for T
where T: Clone,

Source§

fn try_clone(&self) -> Result<T, Error>

Clones self, possibly returning an error.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more