コード例 #1
0
        public 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);
        }
コード例 #2
0
        public Expression <Action <BinaryReader, Action <int, IData>, int> > CreateLoadMethod()
        {
            var reader = Expression.Parameter(typeof(BinaryReader), "reader");
            var values = Expression.Parameter(typeof(Action <int, IData>), "func");
            var count  = Expression.Parameter(typeof(int), "count");

            var array = Expression.Variable(typeof(Data <>).MakeGenericType(Type).MakeArrayType());

            var body = DataType.IsPrimitiveType(Type) ?
                       IndexerPersistHelper.SingleSlotCreateLoadBody(Type, true, 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(Data <>).MakeGenericType(Type).GetConstructor(new Type[] { }))),
                                        Expression.Assign(Expression.ArrayAccess(array, i).Value(), Expression.New(Type.GetConstructor(new Type[] { }))),
                                        Expression.Call(values, values.Type.GetMethod("Invoke"), i, Expression.ArrayAccess(array, i))));
            }, Expression.Label(), count),
                                        IndexerPersistHelper.CreateLoadBody(Type, true, reader, array, count, MembersOrder, Persists)
                                        );

            return(Expression.Lambda <Action <BinaryReader, Action <int, IData>, int> >(body, new ParameterExpression[] { reader, values, count }));
        }
コード例 #3
0
 public DataIndexerPersist(Type T, Func <Type, MemberInfo, int> membersOrder = null)
     : this(T, IndexerPersistHelper.GetDefaultPersists(T, membersOrder), membersOrder)
 {
 }
コード例 #4
0
ファイル: IndexerPersist.cs プロジェクト: wondial/STS.General
 public IndexerPersist(Func <Type, MemberInfo, int> membersOrder = null)
     : this(IndexerPersistHelper.GetDefaultPersists(typeof(T), membersOrder), membersOrder)
 {
 }