示例#1
0
            public void AddDbParameterInfo(string paramName, MemberInfo memberInfo)
            {
                Func <object, object> valueGetter;
                Type memberType;

                // 不是属性就必须是字段,不允许其他情况。
                var propertyInfo = memberInfo as PropertyInfo;

                if (propertyInfo == null)
                {
                    var fieldInfo = (FieldInfo)memberInfo;
                    valueGetter = FieldAccessorGenerator.CreateGetter(fieldInfo);
                    memberType  = fieldInfo.FieldType;
                }
                else
                {
                    valueGetter = PropertyAccessorGenerator.CreateGetter(propertyInfo);
                    memberType  = propertyInfo.PropertyType;
                }

                var info = new DbParameterInfo
                {
                    Name        = paramName,
                    Type        = memberType,
                    ValueGetter = valueGetter
                };

                _parameterInfos.Add(info);
            }
示例#2
0
        private static MemberSetupInfo BuildSetupInfo(int dataColIndex, Type dataFieldType, MemberInfo memberInfo)
        {
            var info = new MemberSetupInfo {
                Index = dataColIndex
            };

            var propInfo = memberInfo as PropertyInfo;

            if (propInfo != null)
            {
                var propertyType   = propInfo.PropertyType;
                var underlyingType = ReflectionUtils.GetUnderlyingType(propertyType);
                info.MemberUnderlyingType = underlyingType;
                info.NeedConvertType      = !propertyType.IsAssignableFrom(dataFieldType);
                info.IsEnum     = underlyingType.IsEnum;
                info.CanBeNull  = ReflectionUtils.IsNullable(propertyType);
                info.Setter     = PropertyAccessorGenerator.CreateSetter(propInfo);
                info.MemberName = propInfo.Name;
            }
            else
            {
                var fieldInfo      = (FieldInfo)memberInfo;
                var fieldType      = fieldInfo.FieldType;
                var underlyingType = ReflectionUtils.GetUnderlyingType(fieldType);
                info.MemberUnderlyingType = underlyingType;
                info.NeedConvertType      = !fieldType.IsAssignableFrom(dataFieldType);
                info.IsEnum     = underlyingType.IsEnum;
                info.CanBeNull  = ReflectionUtils.IsNullable(fieldType);
                info.Setter     = FieldAccessorGenerator.CreateSetter(fieldInfo);
                info.MemberName = fieldInfo.Name;
            }

            return(info);
        }
示例#3
0
            public void AddDbParameterInfo(string paramName, MemberInfo memberInfo)
            {
                var isPropertyInfo = memberInfo is PropertyInfo;
                var memberType     = isPropertyInfo
                    ? ((PropertyInfo)memberInfo).PropertyType
                    : ((FieldInfo)memberInfo).FieldType;
                var dbType = DbTypeConvert.LookupDbType(memberType);

                if (dbType == DbTypeConvert.NotSupporteDbType)
                {
                    throw new NotSupportedException(string.Format(
                                                        "The type {0} can not be converted to a DbType.", memberType));
                }

                var info = new DbParameterInfo();

                info.Name        = paramName;
                info.DbType      = dbType;
                info.IsString    = memberType == typeof(string);
                info.ValueGetter = isPropertyInfo
                    ? PropertyAccessorGenerator.CreateGetter((PropertyInfo)memberInfo)
                    : FieldAccessorGenerator.CreateGetter((FieldInfo)memberInfo);

                _parameterInfos.Add(info);
            }
示例#4
0
        public static void DoPass(RewriteGlobalContext context)
        {
            foreach (var assemblyContext in context.Assemblies)
            {
                foreach (var typeContext in assemblyContext.Types)
                {
                    foreach (var fieldContext in typeContext.Fields)
                    {
                        if (typeContext.ComputedTypeSpecifics == TypeRewriteContext.TypeSpecifics.BlittableStruct && !fieldContext.OriginalField.IsStatic)
                        {
                            continue;
                        }

                        var field             = fieldContext.OriginalField;
                        var unmangleFieldName = fieldContext.UnmangledName;

                        var property = new PropertyDefinition(unmangleFieldName, PropertyAttributes.None,
                                                              assemblyContext.RewriteTypeRef(fieldContext.OriginalField.FieldType));
                        typeContext.NewType.Properties.Add(property);

                        FieldAccessorGenerator.MakeGetter(field, fieldContext, property, assemblyContext.Imports);
                        FieldAccessorGenerator.MakeSetter(field, fieldContext, property, assemblyContext.Imports);
                    }
                }
            }
        }
        public static void DoPass(RewriteGlobalContext context)
        {
            foreach (var assemblyContext in context.Assemblies)
            {
                foreach (var typeContext in assemblyContext.Types)
                {
                    foreach (var fieldContext in typeContext.Fields)
                    {
                        if (typeContext.OriginalType.IsValueType && !fieldContext.OriginalField.IsStatic)
                        {
                            continue;
                        }

                        var field             = fieldContext.OriginalField;
                        var unmangleFieldName = fieldContext.UnmangledName;

                        var property = new PropertyDefinition(unmangleFieldName, PropertyAttributes.None,
                                                              assemblyContext.RewriteTypeRef(fieldContext.OriginalField.FieldType));
                        typeContext.NewType.Properties.Add(property);

                        var getter = FieldAccessorGenerator.MakeGetter(field, fieldContext.PointerField, property);
                        var setter = FieldAccessorGenerator.MakeSetter(field, fieldContext.PointerField, property);
                        typeContext.NewType.Methods.Add(getter);
                        typeContext.NewType.Methods.Add(setter);
                    }
                }
            }
        }