private static Delegate CreateSetter <T>(PropertyInfo property) { switch (Type.GetTypeCode(typeof(T))) { case TypeCode.Boolean: if (typeof(FormatBoolean).IsAssignableFrom(property.PropertyType)) { Func <object, FormatBoolean> fn = FastAccessor.CreateGetter <FormatBoolean>(property); Action <object, bool> ret = (o, v) => { fn(o).Value = v; }; return(ret); } break; case TypeCode.Int32: if (typeof(FormatInteger).IsAssignableFrom(property.PropertyType)) { Func <object, FormatInteger> fn = FastAccessor.CreateGetter <FormatInteger>(property); Action <object, int> ret = (o, v) => { fn(o).Value = v; }; return(ret); } break; case TypeCode.Int64: if (typeof(FormatLong).IsAssignableFrom(property.PropertyType)) { Func <object, FormatLong> fn = FastAccessor.CreateGetter <FormatLong>(property); Action <object, long> ret = (o, v) => { fn(o).Value = v; }; return(ret); } break; case TypeCode.Double: if (typeof(FormatDouble).IsAssignableFrom(property.PropertyType)) { Func <object, FormatDouble> fn = FastAccessor.CreateGetter <FormatDouble>(property); Action <object, double> ret = (o, v) => { fn(o).Value = v; }; return(ret); } break; case TypeCode.String: if (typeof(FormatString).IsAssignableFrom(property.PropertyType)) { Func <object, FormatString> fn = FastAccessor.CreateGetter <FormatString>(property); Action <object, string> ret = (o, v) => { fn(o).Value = v; }; return(ret); } break; default: if (typeof(FormatBytes).IsAssignableFrom(property.PropertyType)) { Func <object, FormatBytes> fn = FastAccessor.CreateGetter <FormatBytes>(property); Action <object, byte[]> ret = (o, v) => { fn(o).Value = v; }; return(ret); } break; } return(FastAccessor.CreateSetter <T>(property)); }
private static Delegate CreateGetter <T>(FieldInfo field) { switch (Type.GetTypeCode(typeof(T))) { case TypeCode.Boolean: if (typeof(FormatBoolean).IsAssignableFrom(field.FieldType)) { Func <object, FormatBoolean> fn = FastAccessor.CreateGetter <FormatBoolean>(field); Func <object, bool> ret = o => fn(o).Value; return(ret); } break; case TypeCode.Int32: if (typeof(FormatInteger).IsAssignableFrom(field.FieldType)) { Func <object, FormatInteger> fn = FastAccessor.CreateGetter <FormatInteger>(field); Func <object, int> ret = o => fn(o).Value; return(ret); } break; case TypeCode.Int64: if (typeof(FormatLong).IsAssignableFrom(field.FieldType)) { Func <object, FormatLong> fn = FastAccessor.CreateGetter <FormatLong>(field); Func <object, long> ret = o => fn(o).Value; return(ret); } break; case TypeCode.Double: if (typeof(FormatDouble).IsAssignableFrom(field.FieldType)) { Func <object, FormatDouble> fn = FastAccessor.CreateGetter <FormatDouble>(field); Func <object, double> ret = o => fn(o).Value; return(ret); } break; case TypeCode.String: if (typeof(FormatString).IsAssignableFrom(field.FieldType)) { Func <object, FormatString> fn = FastAccessor.CreateGetter <FormatString>(field); Func <object, string> ret = o => fn(o).Value; return(ret); } break; default: if (typeof(FormatBytes).IsAssignableFrom(field.FieldType)) { Func <object, FormatBytes> fn = FastAccessor.CreateGetter <FormatBytes>(field); Func <object, byte[]> ret = o => fn(o).Value; return(ret); } break; } return(FastAccessor.CreateGetter <T>(field)); }