Created
August 7, 2009 15:44
-
-
Save tncbbthositg/163966 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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