作者:.NET开发
项目:System.ComponentMode
private bool _myVal = false;
[DefaultValue(false)]
public bool MyProperty
{
get
{
return _myVal;
}
set
{
_myVal = value;
}
}
作者:.NET开发
项目:System.ComponentMode
// Gets the attributes for the property.
AttributeCollection attributes =
TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;
/* Prints the default value by retrieving the DefaultValueAttribute
* from the AttributeCollection. */
DefaultValueAttribute myAttribute =
(DefaultValueAttribute) attributes[typeof(DefaultValueAttribute)];
Console.WriteLine("The default value is: " + myAttribute.Value.ToString());