Struct PropertyBuilder
pub struct PropertyBuilder { /* private fields */ }Expand description
Builder for creating Property metadata entries.
PropertyBuilder provides a fluent API for creating Property table entries
with validation and automatic heap management. Property entries define
named attributes that can be accessed through getter and setter methods,
enabling encapsulated data access patterns in .NET types.
§Property Types
Properties can represent various data access patterns:
- Instance Properties: Bound to specific object instances
- Static Properties: Associated with the type itself
- Indexed Properties: Properties that accept parameters (indexers)
- Auto-Properties: Properties with compiler-generated backing fields
§Method Association
Properties are linked to their implementation methods through the
MethodSemantics table (created separately):
- Getter Method: Retrieves the property value
- Setter Method: Sets the property value
- Other Methods: Additional property-related methods
§Examples
let assembly = CilAssembly::new(view);
let mut context = BuilderContext::new(assembly);
// Create a property signature for System.String
let string_property_sig = &[0x08, 0x1C]; // PROPERTY calling convention + ELEMENT_TYPE_OBJECT
// Create a public instance property
let property = PropertyBuilder::new()
.name("Value")
.flags(0x0000) // No special flags
.signature(string_property_sig)
.build(&mut context)?;
// Create a property with special naming
let special_property = PropertyBuilder::new()
.name("Item") // Indexer property
.flags(0x0200) // SpecialName
.signature(string_property_sig)
.build(&mut context)?;Implementations§
§impl PropertyBuilder
impl PropertyBuilder
pub fn new() -> Self
pub fn new() -> Self
Creates a new PropertyBuilder.
§Returns
A new crate::metadata::tables::property::PropertyBuilder instance ready for configuration.
pub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
Sets the property name.
Property names are used for reflection, debugging, and binding operations. Common naming patterns include Pascal case for public properties and special names like “Item” for indexer properties.
§Arguments
name- The property name (must be a valid identifier)
§Returns
Self for method chaining.
pub fn flags(self, flags: u32) -> Self
pub fn flags(self, flags: u32) -> Self
Sets the property flags (attributes).
Property flags control special behaviors and characteristics.
Common flag values from crate::metadata::tables::PropertyAttributes:
0x0000: No special flags (default for most properties)0x0200: SPECIAL_NAME - Property has special naming conventions0x0400: RT_SPECIAL_NAME - Runtime should verify name encoding0x1000: HAS_DEFAULT - Property has default value in Constant table
§Arguments
flags- The property attribute flags bitmask
§Returns
Self for method chaining.
pub fn signature(self, signature: &[u8]) -> Self
pub fn signature(self, signature: &[u8]) -> Self
Sets the property type signature.
The signature defines the property’s type and parameters using ECMA-335 signature encoding. Property signatures start with a calling convention byte followed by the type information.
Common property signature patterns:
[0x08, 0x08]: PROPERTY + int32 property[0x08, 0x0E]: PROPERTY + string property[0x28, 0x01, 0x08, 0x08]: PROPERTY + HASTHIS + 1 param + int32 + int32 (indexer)[0x08, 0x1C]: PROPERTY + object property
§Arguments
signature- The property type signature bytes
§Returns
Self for method chaining.
pub fn build(self, context: &mut BuilderContext) -> Result<Token>
pub fn build(self, context: &mut BuilderContext) -> Result<Token>
Builds the property and adds it to the assembly.
This method validates all required fields are set, adds the name and signature to the appropriate heaps, creates the raw property structure, and adds it to the Property table.
Note: This only creates the Property table entry. Method associations (getter, setter) must be created separately using MethodSemantics builders.
§Arguments
context- The builder context for managing the assembly
§Returns
A crate::metadata::token::Token representing the newly created property, or an error if
validation fails or required fields are missing.
§Errors
- Returns error if name is not set
- Returns error if flags are not set
- Returns error if signature is not set
- Returns error if heap operations fail
- Returns error if table operations fail
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PropertyBuilder
impl RefUnwindSafe for PropertyBuilder
impl Send for PropertyBuilder
impl Sync for PropertyBuilder
impl Unpin for PropertyBuilder
impl UnwindSafe for PropertyBuilder
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
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 more