Beispiel #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);
            }
Beispiel #2
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);
            }