private static ValueTypeChange ValueTypeChangeFor(TreeGridNode node, int depth) { IType omnType = FieldTypeFor(node); if (omnType.IsCollection || omnType.IsArray) { return(null); } Type type = Type.GetType(omnType.FullName); if (type == null) { return(null); } if (type.IsValueType) { ValueTypeChange change = ValueTypeChangeFor(node.Parent, depth + 1); if (change != null) { change.FieldPath.Add(FieldInfoFor(node)); } return(change); } return(depth == 0 ? null : new ValueTypeChange(node.Tag)); }
/** * Each node in "details view" holds a reference for its corresponding * object in the object model. While this works fine with reference * types, it fails miserably with nested value types. * * For more details see OMNUnitTest.RenderHierarchyTestCase. */ public static bool TryUpdateValueType(TreeGridNode node, object newValue) { if (node == null || node.Parent == null) { return(false); } ValueTypeChange change = ValueTypeChangeFor(node.Parent, 0); if (change == null) { return(false); } FieldInfo fieldInfo = FieldInfoFor(node); if (fieldInfo == null) { return(false); } fieldInfo.SetValueDirect(TypedReference.MakeTypedReference(change.TargetObject, change.FieldPath.ToArray()), newValue); return(true); }
public static void PropagateValueTypeChanges(ValueTypeChange[] changes) { foreach (ValueTypeChange change in changes) { if (!(change.Value is ValueType)) break; try { SetProperty(change.Target, change.Member, change.Value); } catch (MissingFieldException) { // hit a readonly property break; } } }