Example #1
0
        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));
        }