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
SignatureMethod: Contains parameter lists for complete method signaturesSignatureProperty: Uses parameters for indexed property signaturescrate::metadata::token::Token: For custom modifier token references
Fields§
§modifiers: CustomModifiersCustom 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: boolWhether 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 modificationout: Output parameter that must be assignedin: Read-only reference for performance- Return values: Reference returns for efficient access
base: TypeSignatureThe 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
impl Clone for SignatureParameter
§fn clone(&self) -> SignatureParameter
fn clone(&self) -> SignatureParameter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for SignatureParameter
impl Debug for SignatureParameter
§impl Default for SignatureParameter
impl Default for SignatureParameter
§fn default() -> SignatureParameter
fn default() -> SignatureParameter
§impl Display for SignatureParameter
impl Display for SignatureParameter
§impl PartialEq for SignatureParameter
impl PartialEq for SignatureParameter
impl StructuralPartialEq for SignatureParameter
Auto Trait Implementations§
impl Freeze for SignatureParameter
impl RefUnwindSafe for SignatureParameter
impl Send for SignatureParameter
impl Sync for SignatureParameter
impl Unpin for SignatureParameter
impl UnsafeUnpin for SignatureParameter
impl UnwindSafe for SignatureParameter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for T
impl<T> Downcast for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more