public void IsEmpty_OnEmptyClass_ReturnsTrue() { SerializationContext context = new SerializationContext(); TypeData EmptyClassHandler = new TypeData(typeof(EmptyClass), context); Assert.IsTrue(EmptyClassHandler.IsEmpty, "IsEmpty should return true on class with no properties/fields"); }
public void IsEmpty_OnClassWithOnlyIgnoredFields_ReturnsTrue() { SerializationContext context = new SerializationContext(); TypeData IgnoredClassHandler = new TypeData(typeof(IgnoredFieldClass), context); Assert.IsTrue(IgnoredClassHandler.IsEmpty, "IsEmpty should return true on class with all properties/fields ignored"); }
public ConverterUtil(Type forType, SerializationContext context) { _handler = context.GetTypeHandler(forType); }
protected virtual void EvaluateItem(object existingObject, IDeserializerHandler deserializer, TypeData typeHandler, KeyValueExpression Item) { // evaluate the item and let it assign itself? IPropertyData hndlr = typeHandler.FindPropertyByAlias(Item.Key); if (hndlr == null) { switch (this.Config.MissingPropertyAction) { case MissingPropertyOptions.Ignore: return; case MissingPropertyOptions.ThrowException: throw new Exception(string.Format("Could not find property {0} for type {1}", Item.Key, typeHandler.ForType)); default: throw new InvalidOperationException("Unhandled MissingPropertyAction: " + this.Config.MissingPropertyAction); } } if (hndlr.Ignored) { switch (Config.IgnoredPropertyAction) { case SerializationContext.IgnoredPropertyOption.Ignore: return; case SerializationContext.IgnoredPropertyOption.SetIfPossible: if (!hndlr.CanWrite) return; break; case SerializationContext.IgnoredPropertyOption.ThrowException: throw new Exception(string.Format("Can not set property {0} for type {1} because it is ignored and IgnorePropertyAction is set to ThrowException", Item.Key, typeHandler.ForType)); } } Expression valueExpression = Item.ValueExpression; valueExpression.ResultType = hndlr.PropertyType; object result = null; TypeConverterExpressionHandler converterHandler = null; IJsonTypeConverter converter = null; if (hndlr.HasConverter) { converterHandler = (TypeConverterExpressionHandler)Config.ExpressionHandlers.Find(typeof(TypeConverterExpressionHandler)); converter = hndlr.TypeConverter; } if (!hndlr.CanWrite) { result = hndlr.GetValue(existingObject); if (converterHandler != null) { converterHandler.Evaluate(valueExpression, result, deserializer, converter); } else { deserializer.Evaluate(valueExpression, result); } } else { if (hndlr.HasConverter) hndlr.SetValue(existingObject, converterHandler.Evaluate(valueExpression, deserializer, converter)); else hndlr.SetValue(existingObject, deserializer.Evaluate(valueExpression)); } }
public override void SetValue(object instance, object value) { (_setter ?? (_setter = TypeData.GetCompiledSetter(member)))(instance, value); }
public MethodPairPropertyHandler(Type DeclaringType, TypeData parent, string Name) : this(DeclaringType, parent, "Get" + Name, "Set" + Name, Name) { }
public FirstPH(Type forType, TypeData parent) : base(forType, parent, "FirstName") { }
protected MemberInfoPropertyDataBase(MemberInfo member, TypeData parent) : base(member.DeclaringType, parent) { this.member = member; }
public AgePH(Type forType, TypeData parent) : base(forType, parent, "Age") { }
public CustomerPHBase(Type forType, TypeData parent, string name) : base(forType, parent) { _name = name; }
public SSNPH(Type forType, TypeData parent) : base(forType, parent, "Ssn") { }
public PhonePH(Type forType, TypeData parent) : base(forType, parent, "Phone") { }
/// <summary> /// Initializes an instance of PropertyData with the specified PropertyInfo object that is /// not a constructor argument. /// </summary> /// <param name="property">the backing property object</param> public PropertyData(PropertyInfo property, TypeData parent) : base(property, parent) { Initialize(); }
public void IsEmpty_OnNonEmptyClass_ReturnsFalse() { SerializationContext context = new SerializationContext(); TypeData SimpleObjectHandler = new TypeData(typeof(SimpleObject), context); Assert.IsFalse(SimpleObjectHandler.IsEmpty, "IsEmpty should return false on class with properties/fields"); }
public LastPH(Type forType, TypeData parent) : base(forType, parent, "LastName") { }
/// <summary> /// Constructs a FieldHandler for a field on a type that is not a constructor /// parameter /// </summary> /// <param name="field">field info</param> public FieldData(FieldInfo field, TypeData parent) : base(field, parent) { }
protected virtual ITypeData CreateNew(Type forType) { return(TypeData.Create(forType, this)); }
public override object GetValue(object instance) { return((_getter ?? (_getter = TypeData.GetCompiledGetter(member)))(instance)); }
public DynamicPropertyData(PropertyInfo PropertyInfo, TypeData parent) : base(PropertyInfo, parent) { Initialize(); }
public MethodPairPropertyHandler(Type DeclaringType, TypeData parent, string GetMethod, string SetMethod, string PropertyName) : base(DeclaringType, parent) { _getMethod = GetMethod; _setMethod = SetMethod; _propertyName = PropertyName; }
/// <summary> /// Initializes an instance for the specific declaring type /// </summary> /// <param name="forType">the declaring type for this property</param> protected AbstractPropertyData(Type forType, TypeData parent) : base(forType) { this.parent = parent; }
/// <summary> /// Initializes an instance for the specific declaring type /// </summary> /// <param name="forType">the declaring type for this property</param> protected AbstractPropertyData(Type forType, TypeData parent) : base(forType) { this.Parent = parent; }