コード例 #1
0
        private Expression makeFieldReader(FieldFunctionInfo ffi)
        {
            if (ffi.DeserializerFactory != null)
            {
                var mi = BuildUtils.CustomFieldMi.MakeGenericMethod(ffi.ResultType);
                var customDeserializer = Expression.Constant(ffi.DeserializerFactory.CreateInstance(ffi.ResultType));
                return(Expression.Call(null, mi, _pDeserializer, customDeserializer, Expression.Constant(ffi.Name), _pCfgNode, Expression.Constant(ffi.Required)));
            }

            if (!SimpleTypes.Converter.IsPrimitive(ffi.ResultType))
            {
                if (ffi.ResultType.IsArray)
                {
                    var itemType = ffi.ResultType.GetElementType();
                    var mi       = BuildUtils.ToArrayMi.MakeGenericMethod(itemType);
                    return(Expression.Call(null, mi, _pDeserializer, Expression.Constant(ffi.Name), _pCfgNode));
                }

                if (BuildUtils.IsCollection(ffi.ResultType))
                {
                    var itemType = ffi.ResultType.GetGenericArguments()[0];
                    var mi       = BuildUtils.ToListMi.MakeGenericMethod(itemType);
                    return(Expression.Call(null, mi, _pDeserializer, Expression.Constant(ffi.Name), _pCfgNode));
                }
            }

            {
                var mi = BuildUtils.ReadFieldMi.MakeGenericMethod(ffi.ResultType);
                return(Expression.Call(null, mi, _pDeserializer, Expression.Constant(ffi.Name), _pCfgNode, Expression.Constant(ffi.Required)));
            }
        }
コード例 #2
0
        private Expression makeFieldReader(FieldFunctionInfo ffi)
        {
            if (ffi.DeserializerFactory != null)
            {
                var mi = BuildUtils.CustomFieldMi.MakeGenericMethod(ffi.ResultType);
                var customDeserializer = Expression.Constant(ffi.DeserializerFactory.CreateInstance(ffi.ResultType));
                return Expression.Call(null, mi, _pDeserializer, customDeserializer, Expression.Constant(ffi.Name), _pCfgNode, Expression.Constant(ffi.Required));
            }

            if (!SimpleTypes.Converter.IsPrimitive(ffi.ResultType))
            {
                if (ffi.ResultType.IsArray)
                {
                    var itemType = ffi.ResultType.GetElementType();
                    var mi = BuildUtils.ToArrayMi.MakeGenericMethod(itemType);
                    return Expression.Call(null, mi, _pDeserializer, Expression.Constant(ffi.Name), _pCfgNode);
                }

                if (BuildUtils.IsCollection(ffi.ResultType))
                {
                    var itemType = ffi.ResultType.GetGenericArguments()[0];
                    var mi = BuildUtils.ToListMi.MakeGenericMethod(itemType);
                    return Expression.Call(null, mi, _pDeserializer, Expression.Constant(ffi.Name), _pCfgNode);
                }
            }

            {
                var mi = BuildUtils.ReadFieldMi.MakeGenericMethod(ffi.ResultType);
                return Expression.Call(null, mi, _pDeserializer, Expression.Constant(ffi.Name), _pCfgNode, Expression.Constant(ffi.Required));
            }
        }