Esempio n. 1
0
        internal static void Factory(DynamicFormatterAssembly assembly, ObjectSerializationInfo objectSerializationInfo)
        {
            ParameterExpression instance = Expression.Parameter(objectSerializationInfo.Type, "value");

            Expression <Serialize <T> >   serializeExpression   = Array3DynamicExpressionBuild.BuildSerializeLambda <T>(objectSerializationInfo, instance);
            Expression <Size <T> >        sizeExpression        = Array3DynamicExpressionBuild.BuildSizeLambda <T>(objectSerializationInfo, instance);
            Expression <Deserialize <T> > deserializeExpression = Array3DynamicExpressionBuild.BuildDeserializeLambda <T>(objectSerializationInfo);

            Serialize   = serializeExpression.Compile();
            Size        = sizeExpression.Compile();
            Deserialize = deserializeExpression.Compile();

#if NETFRAMEWORK
            TypeBuilder   typeBuilder       = assembly.DefineFormatterDelegateType(objectSerializationInfo.Type);
            MethodBuilder serializeDelegate = TypeBuildHelper.DefineSerializeDelegate(typeBuilder, typeof(T));
            serializeExpression.CompileToMethod(serializeDelegate);
            MethodBuilder sizeDelegate = TypeBuildHelper.DefineSizeDelegate(typeBuilder, typeof(T));
            sizeExpression.CompileToMethod(sizeDelegate);
            MethodBuilder deserializeDelegate = TypeBuildHelper.DefineDeserializeDelegate(typeBuilder, typeof(T));
            deserializeExpression.CompileToMethod(deserializeDelegate);
            typeBuilder.CreateTypeInfo();
#endif
        }