Skip to content

Instantly share code, notes, and snippets.

@rauhryan
Created February 25, 2010 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rauhryan/314573 to your computer and use it in GitHub Desktop.
Save rauhryan/314573 to your computer and use it in GitHub Desktop.
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