Skip to content

Instantly share code, notes, and snippets.

@tncbbthositg
Created August 7, 2009 15:44
Show Gist options
  • Save tncbbthositg/163966 to your computer and use it in GitHub Desktop.
Save tncbbthositg/163966 to your computer and use it in GitHub Desktop.
namespace PropertyDefaultAttributeTestConsole
{
class Program
{
static void Main(string[] args)
{
Person pat = new Person();
Console.WriteLine(pat); // "Caldwell, Pat"
Console.WriteLine(pat.Fiance); // "Woody, Lauren"
Console.WriteLine(pat.Friends.Count); // 0
pat.Friends.Add(new Person("James", "Brechtel"));
Console.WriteLine(pat.Friends.Count); // 1
pat.FirstName = "Patrick";
Console.WriteLine(pat); // "Caldwell, Patrick"
Console.ReadLine();
}
}
class Person
{
public Person(string first, string last)
{
FirstName = first;
LastName = last;
}
public Person()
{ }
[PropertyDefault(DefaultValue = "Pat")]
public string FirstName { get; set; }
[PropertyDefault(DefaultValue = "Caldwell")]
public string LastName { get; set; }
[PropertyDefault("Please enter a profile!")]
public StringBuilder Profile { get; set; }
[PropertyDefault]
public List<Person> Friends { get; set; }
[PropertyDefault("Lauren", "Woody")]
public Person Fiance { get; set; }
public override string ToString()
{
return string.Format("{0}, {1}", LastName, FirstName);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment