icubilla / jsonexserializer

Automatically exported from code.google.com/p/jsonexserializer
0 stars 0 forks source link

Add AttributeService for processing Property and Class custom attributes #42

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago

Original comment by elliott....@gmail.com on 2 Jul 2009 at 12:24

GoogleCodeExporter commented 9 years ago
Release 3.1

Original comment by elliott....@gmail.com on 16 Apr 2010 at 3:51