This is an idea to abstract out the handling of custom attributes from
inside the code to make them more extensible. This will accomplish a
couple of things.
1) Provide custom properties to TypeConverters by overriding or providing a
different attribute
2) Reuse existing attributes from .NET framework or other libraries that
have similar meanings to JsonEx attributes, such as XmlIgnore to specify
ignored fields.
3) Add custom behavior in places where attributes are supported. These
include Type metadata, property metadata, collection handlers, and type
converters.
The current custom attributes are:
JsonExProperty
JsonExIgnore
JsonExCollection
ConstructorParameter
JsonConvert
The existing code checks for the existence of one of the pre-defined
attributes and then uses its properties to initialize or modify the current
object.
New code might look something like this:
PropertyInfo p;
Context.AttributeService.ProcessAttributes(p, this);
Handlers would be registered as:
Context.AttributeService.RegisterHandler(typeof(JsonExIgnoreAttribute), new
JsonIgnoreHandler());
Handler class:
public class JsonIgnoreHandler {
public void ProcessAttribute(Attribute a, object target) {
if (target is IPropertyData)
((IPropertyData) target).Ignored = true;
}
}
Specify XmlIgnore as the ignore attribute:
Context.AttributeService.RegisterHandler(typeof(XmlIgnore), new
JsonIgnoreHandler());
Original issue reported on code.google.com by elliott....@gmail.com on 11 Mar 2009 at 2:55
Original issue reported on code.google.com by
elliott....@gmail.com
on 11 Mar 2009 at 2:55