Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person
- {
- public Person()
- {
- Name = "Default Name";
- }
- public string Name { get; set; }
- }
- private string name = "Default Name";
- public string Name
- {
- get
- {
- return name;
- }
- set
- {
- name = value;
- }
- }
- class Person
- {
- public Person()
- {
- //do anything before variable assignment
- //assign initial values
- Name = "Default Name";
- //do anything after variable assignment
- }
- public string Name { get; set; }
- }
- class Person
- {
- private string _name;
- public string Name
- {
- get
- {
- return string.IsNullOrEmpty(_name) ? "Default Name" : _name;
- }
- set { _name = value; }
- }
- }
- private bool bShowGroup ;
- [Description("Show the group table"), Category("Sea"),DefaultValue(true)]
- public bool ShowGroup
- {
- get { return bShowGroup; }
- set { bShowGroup = value; }
- }
- public class DefaultValuesTest
- {
- public DefaultValuesTest()
- {
- foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this))
- {
- DefaultValueAttribute myAttribute = (DefaultValueAttribute)property.Attributes[typeof(DefaultValueAttribute)];
- if (myAttribute != null)
- {
- property.SetValue(this, myAttribute.Value);
- }
- }
- }
- public void DoTest()
- {
- var db = DefaultValueBool;
- var ds = DefaultValueString;
- var di = DefaultValueInt;
- }
- [System.ComponentModel.DefaultValue(true)]
- public bool DefaultValueBool { get; set; }
- [System.ComponentModel.DefaultValue("Good")]
- public string DefaultValueString { get; set; }
- [System.ComponentModel.DefaultValue(27)]
- public int DefaultValueInt { get; set; }
- }
- class Person
- {
- /// Gets/sets a value indicating whether auto
- /// save of review layer is enabled or not
- [ System.ComponentModel.DefaultValue(true)]
- public bool AutoSaveReviewLayer { get; set; }
- }
- class Person
- {
- private string _name;
- [DefaultValue(true)]
- public string Name
- {
- get { return _name; }
- set { _name = value; }
- }
- }
Add Comment
Please, Sign In to add comment