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

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

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

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 conventions
  • 0x0400: RT_SPECIAL_NAME - Runtime should verify name encoding
  • 0x1000: 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

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>

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§

§

impl Default for PropertyBuilder

§

fn default() -> Self

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

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> 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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<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> Same for T

Source§

type Output = T

Should always be Self
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.