Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save casper-rasmussen/5c5337c809d98680e0b42b46cf67a47c to your computer and use it in GitHub Desktop.
Save casper-rasmussen/5c5337c809d98680e0b42b46cf67a47c to your computer and use it in GitHub Desktop.
[Serializable]
[PropertyDefinitionTypePlugIn(DisplayName = "PropertyCategoryList")]
public class PropertyCategoryListPropertyDefinition : PropertyData
{
private EPiServer.Core.CategoryList _inner;
public PropertyCategoryListPropertyDefinition()
: this(new EPiServer.Core.CategoryList()) { }
public PropertyCategoryListPropertyDefinition(EPiServer.Core.CategoryList inner)
: base()
{
this._inner = inner;
}
public override PropertyData ParseToObject(string value)
{
EPiServer.Core.CategoryList inner = EPiServer.Core.CategoryList.Parse(value);
return new PropertyCategoryListPropertyDefinition(inner);
}
public override void ParseToSelf(string value)
{
if (QualifyAsNullString(value))
Value = new EPiServer.Core.CategoryList();
Value = EPiServer.Core.CategoryList.Parse(value);
}
protected override void SetDefaultValue()
{
ThrowIfReadOnly();
this._inner = new EPiServer.Core.CategoryList();
}
public override PropertyData CreateWritableClone()
{
var clone = (PropertyCategoryListPropertyDefinition)base.CreateWritableClone();
clone._inner = this._inner.CreateWritableClone() as EPiServer.Core.CategoryList;
return clone;
}
public override PropertyData Copy()
{
var copy = (PropertyCategoryListPropertyDefinition)base.Copy();
copy._inner = this._inner.Copy() as EPiServer.Core.CategoryList;
return copy;
}
public override object SaveData(PropertyDataCollection properties)
{
return this._inner.ToString();
}
public override bool IsModified
{
get
{
return base.IsModified || this._inner.IsModified;
}
set
{
ThrowIfReadOnly();
this._inner.IsModified = value;
base.IsModified = value;
}
}
public override bool Equals(object obj)
{
var compareTo = obj as EPiServer.Core.CategoryList;
if (compareTo == null)
return false;
return this._inner.Equals(compareTo);
}
public override Type PropertyValueType
{
get { return typeof(EPiServer.Core.CategoryList); }
}
public override PropertyDataType Type
{
get { return PropertyDataType.String; }
}
public override object Value
{
get
{
if (IsNull)
return null;
return this._inner;
}
set
{
SetPropertyValue(value, () =>
{
if (value is EPiServer.Core.CategoryList)
{
this._inner = (EPiServer.Core.CategoryList)value;
}
else if (value is string)
{
ParseToSelf((string)value);
}
else
{
throw new ArgumentException(
"Passed object must be of type CategoryList or "
+ "a string that can be de-serialized to a "
+ "CategoryList object.");
}
});
}
}
public override bool IsNull
{
get
{
return this._inner == null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment