public HResult SetProperty(int property, object value)
{
try
{
try
{
if (property < 0)
{
switch ((NiHierarchyProperty)property)
{
case NiHierarchyProperty.FirstChild:
case NiHierarchyProperty.NextSibling:
throw new ArgumentOutOfRangeException("property", NeutralResources.CannotSetProperty);
case NiHierarchyProperty.Parent:
if (value != null && !(value is NiHierarchy))
throw new ArgumentOutOfRangeException("value", NeutralResources.ParentMustBeHierarchy);
return ProcessParentChange((NiHierarchy)value);
case NiHierarchyProperty.Image:
case NiHierarchyProperty.OverlayImage:
if (value != null && !(value is IResource))
throw new ArgumentOutOfRangeException("value", NeutralResources.InvalidPropertyType);
break;
case NiHierarchyProperty.ItemType:
if (value != null && !(value is NiHierarchyType))
throw new ArgumentOutOfRangeException("value", NeutralResources.InvalidPropertyType);
break;
case NiHierarchyProperty.OwnerType:
if (value != null && !(value is Guid))
throw new ArgumentOutOfRangeException("value", NeutralResources.InvalidPropertyType);
break;
case NiHierarchyProperty.Name:
if (value != null && !(value is string))
throw new ArgumentOutOfRangeException("value", NeutralResources.InvalidPropertyType);
string oldName = _name;
_name = (string)value;
if (
_parent != null &&
!String.Equals(_name, oldName, NameComparison)
)
_parent.Reposition(this);
return HResult.OK;
case NiHierarchyProperty.SortPriority:
if (value != null && !(value is int))
throw new ArgumentOutOfRangeException("value", NeutralResources.InvalidPropertyType);
var oldSortPriority = _sortPriority;
_sortPriority = (int?)value;
if (
_parent != null &&
_sortPriority.GetValueOrDefault() != oldSortPriority.GetValueOrDefault()
)
_parent.Reposition(this);
return HResult.OK;
default:
throw new ArgumentOutOfRangeException("property", NeutralResources.UnknownProperty);
}
}
if (value == null)
_properties.Remove(property);
else
_properties[property] = value;
}
finally
{
_connectionPoint.ForAll(p => p.OnPropertyChanged(this, property));
}
return HResult.OK;
}
catch (Exception ex)
{
return ErrorUtil.GetHResult(ex);
}
}