Created
February 25, 2010 14:34
-
-
Save rauhryan/314573 to your computer and use it in GitHub Desktop.
This file contains 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
public class ValueObjectHolder: DomainEntity | |
{ | |
protected ValueObjectHolder() | |
{ | |
Values = new List<ValueObject>(); | |
} | |
public ValueObjectHolder(string key):this() | |
{ | |
Key = key; | |
} | |
public virtual string Key { get; protected set; } | |
public virtual IList<ValueObject> Values { get; set; } | |
public virtual ValueObjectHolder AddValueObject(ValueObject valueObject) | |
{ | |
if (Key.IsEmpty()) | |
throw new InvalidOperationException( | |
"You must specify the ValueObject Key before you can add a child value"); | |
valueObject.Parent = this; | |
valueObject.Key = string.Format("{0}=>{1}", Key, valueObject.Key); | |
Values.Add(valueObject); | |
return this; | |
} | |
} | |
public class ValueObject : DomainEntity | |
{ | |
protected ValueObject() | |
{ | |
} | |
public ValueObject(string key) : this() | |
{ | |
if (key.IsEmpty()) | |
throw new InvalidOperationException("You must specify the ValueObject Key"); | |
Key = key; | |
Value = key; | |
} | |
[NotNullNotEmpty] | |
public virtual string Key { get; set; } | |
[NotNullNotEmpty] | |
public virtual string Value { get; set; } | |
public virtual bool IsDefault { get; set; } | |
public virtual ValueObjectHolder Parent { get; set; } | |
public virtual string GetKey() | |
{ | |
var indexOfLastDelimeter = Key.LastIndexOf("=>") + 2; | |
if (indexOfLastDelimeter == 2) return Key; | |
return Key.Substring(indexOfLastDelimeter, Key.Length-indexOfLastDelimeter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment