/// <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) { }
public DynamicPropertyData(PropertyInfo PropertyInfo, TypeData parent) : base(PropertyInfo, parent) { Initialize(); }
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)); } }
/// <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; }
protected MemberInfoPropertyDataBase(MemberInfo member, TypeData parent) : base(member.DeclaringType, parent) { this.member = member; }
public ConverterUtil(Type forType, SerializationContext context) { _handler = context.GetTypeHandler(forType); }