public void TestGetValue() { DummyClass dummy = new DummyClass { b = true }; Assert.Equal(true, wrapper.GetValue(dummy)); }
/// <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 SerializeValue(IDataAdapter data, object target) { objectsCache.Add(target, maxObjId++); TypeWrapper wrapper = TypeCache.GetWrapper(target.GetType()); if (wrapper.TrySerialize(target, data, this)) { return; } for (int i = 0; i < wrapper.Properties.Count; i++) { PropertyWrapper property = wrapper.Properties[i]; if (property.IsPrivate) { if (!settings.SerializePrivateProperties) { continue; } havePrivateProperties = true; } bool isReadOnly; if (property.ConstructorArg != -1 || // will be used in constructor settings.SerializeReadOnly) { isReadOnly = false; // always serialize } else { isReadOnly = !property.CanWrite; } object value = property.GetValue(target); if (value != null) { SerializeValue(property.MemberType, value, data, new Info(property), isReadOnly); } else if (settings.SerializeNull) { data.AddNullValue(property.Name, property.Location != NanoLocation.SubNode); } } for (int i = 0; i < wrapper.Fields.Count; i++) { FieldWrapper field = wrapper.Fields[i]; if (!settings.IgnoreNotSerialized && field.Info.IsNotSerialized) { continue; } object value = field.GetValue(target); if (value != null) { SerializeValue(field.MemberType, value, data, new Info(field), false); } else if (settings.SerializeNull) { data.AddNullValue(field.Name, field.Location != NanoLocation.SubNode); } } }