private Expression <Action <BinaryWriter, Func <int, IData>, int> > CreateStoreMethod()
        {
            var writer = Expression.Parameter(typeof(BinaryWriter), "writer");
            var values = Expression.Parameter(typeof(Func <int, IData>), "values");
            var count  = Expression.Parameter(typeof(int), "count");

            var idx        = Expression.Variable(typeof(int), "idx");
            var callValues = Expression.Convert(Expression.Call(values, values.Type.GetMethod("Invoke"), idx), typeof(Data <>).MakeGenericType(Type)).Value();

            var body   = IndexerPersistHelper.CreateStoreBody(Type, Persists, writer, callValues, idx, count, MembersOrder);
            var lambda = Expression.Lambda <Action <BinaryWriter, Func <int, IData>, int> >(body, new ParameterExpression[] { writer, values, count });

            return(lambda);
        }
Example #2
0
        public Expression <Action <BinaryWriter, Func <int, T>, int> > CreateStoreMethod()
        {
            var writer = Expression.Parameter(typeof(BinaryWriter), "writer");
            var values = Expression.Parameter(typeof(Func <int, T>), "func");
            var count  = Expression.Parameter(typeof(int), "count");

            var idx        = Expression.Variable(typeof(int), "idx");
            var callValues = Expression.Call(values, values.Type.GetMethod("Invoke"), idx);

            var body = IndexerPersistHelper.CreateStoreBody(Type, Persists, writer, callValues, idx, count, MembersOrder);

            var lambda = Expression.Lambda <Action <BinaryWriter, Func <int, T>, int> >(body, new ParameterExpression[] { writer, values, count });

            return(lambda);
        }
Example #3
0
        public Expression <Action <BinaryReader, Action <int, T>, int> > CreateLoadMethod()
        {
            var reader = Expression.Parameter(typeof(BinaryReader), "reader");
            var values = Expression.Parameter(typeof(Action <int, T>), "func");
            var count  = Expression.Parameter(typeof(int), "count");

            var array = Expression.Variable(typeof(T[]));


            var body = DataType.IsPrimitiveType(Type) ?
                       IndexerPersistHelper.SingleSlotCreateLoadBody(Type, false, values, reader, count, Persists) :
                       Expression.Block(new ParameterExpression[] { array },
                                        Expression.Assign(array, Expression.New(array.Type.GetConstructor(new Type[] { typeof(int) }), count)),
                                        array.For(i =>
            {
                return(Expression.Block(Expression.Assign(Expression.ArrayAccess(array, i), Expression.New(typeof(T).GetConstructor(new Type[] { }))),
                                        Expression.Call(values, values.Type.GetMethod("Invoke"), i, Expression.ArrayAccess(array, i))));
            }, Expression.Label(), count),
                                        IndexerPersistHelper.CreateLoadBody(Type, false, reader, array, count, MembersOrder, Persists)
                                        );

            return(Expression.Lambda <Action <BinaryReader, Action <int, T>, int> >(body, new ParameterExpression[] { reader, values, count }));
        }
Example #4
0
 public IndexerPersist(Func <Type, MemberInfo, int> membersOrder = null)
     : this(IndexerPersistHelper.GetDefaultPersists(typeof(T), membersOrder), membersOrder)
 {
 }
 public DataIndexerPersist(Type T, Func <Type, MemberInfo, int> membersOrder = null)
     : this(T, IndexerPersistHelper.GetDefaultPersists(T, membersOrder), membersOrder)
 {
 }