public void TestSetValue() { DummyClass dummy = new DummyClass { b = false }; wrapper.SetValue(dummy, true); Assert.True(dummy.b); }
/// <summary> /// copy field value from source to target. Deep cloning used if necessary /// </summary> private static void CopyFieldValue(object source, object target, FieldWrapper fieldWrapper, Dictionary <object, object> clonedObjects) { var value = fieldWrapper.GetValue(source); if (value == null) { return; } if (fieldWrapper.CloningMode == CloningMode.Deep) { value = Clone(fieldWrapper.TypeWrapper, value, clonedObjects); } fieldWrapper.SetValue(target, value); }
private void FillObject(TypeWrapper wrapper, object target, IDataAdapter data) { if (wrapper.IsSelfSerializable) { ((INanoSerializable)target).Deserialize(data, this); return; } // read properties for (int i = 0; i < wrapper.Properties.Count; i++) { PropertyWrapper property = wrapper.Properties[i]; // should be already loaded at this time if (property.ConstructorArg != -1 && property.State != NanoState.SerializeSet) { continue; } if (property.Info.GetMethod.IsPrivate && property.Info.SetMethod.IsPrivate && (flags & OptimizationFlags.PrivateProperties) == 0) { continue; } if (property.TypeCategory == TypeCategory.Primitive || property.TypeCategory == TypeCategory.Enum) { if (!property.Info.CanWrite) { continue; } property.SetValue( target, DeserializePrimitive( property.MemberType, data, property.Name, property.Location != NanoLocation.SubNode, (flags & OptimizationFlags.EnumAsValue) != 0 ) ); } else { IDataAdapter subnode = data.GetChild(property.Name); if (subnode != null) { object currentValue = property.GetValue(target); if (currentValue == null) { property.SetValue(target, DeserializeObject(property.MemberType, subnode, null)); } else { DeserializeObject(property.MemberType, subnode, currentValue); } } } } // read fields for (int i = 0; i < wrapper.Fields.Count; i++) { FieldWrapper field = wrapper.Fields[i]; // should be already loaded at this time if (field.ConstructorArg != -1 && field.State != NanoState.SerializeSet) { continue; } if (field.TypeCategory == TypeCategory.Primitive || field.TypeCategory == TypeCategory.Enum) { field.SetValue( target, DeserializePrimitive( field.MemberType, data, field.Name, field.Location != NanoLocation.SubNode, (flags & OptimizationFlags.EnumAsValue) != 0 ) ); } else { IDataAdapter subnode = data.GetChild(field.Name); if (subnode != null) { object value = DeserializeObject(field.MemberType, subnode, null); if (value != null) { field.SetValue(target, value); } } } } }