SetConstant
is a wrapper around TypeBuilder.SetConstantValue()
, which is used to associate compile-time constants with certain IL metadata, most commonly parameters (with default values) and const
fields.
Its usefulness for properties seems rather dubious; it does not affect what value is actually returned by the property's get
accessor. It would seem the default value set via SetConstant()
can only be inspected in the metadata or via reflection. It might be useful if you want to allow someone to determine the default value returned by a property using reflection or IL analysis only, but since the get
accessor is not required to actually return that value, ever, it should be taken with a grain of salt.