Beispiel #1
0
        public IUpdateBuilderDynamic Where(string name, DataTypes parameterType, int size)
        {
            var propertyValue = ObjectReflectionHelper.GetPropertyValueDynamic(Data.Item, name);

            Where(name, propertyValue, parameterType, size);
            return(this);
        }
Beispiel #2
0
 internal AutoMapper(DbCommandData dbCommandData, Type itemType)
 {
     _dbCommandData = dbCommandData;
     _reader        = dbCommandData.Reader.InnerReader;
     _properties    = ObjectReflectionHelper.GetProperties(itemType);
     _fields        = DataReaderHelper.GetDataReaderFields(_reader);
 }
Beispiel #3
0
        internal void AutoMapColumnsAction <T>(params Expression <Func <T, object> >[] ignorePropertyExpressions)
        {
            VerifyAutoMapAlreadyCalled();

            var properties          = ObjectReflectionHelper.GetProperties(_data.Item.GetType());
            var ignorePropertyNames = new HashSet <string>();

            if (ignorePropertyExpressions != null)
            {
                foreach (var ignorePropertyExpression in ignorePropertyExpressions)
                {
                    var ignorePropertyName = new PropertyExpressionParser <T>(_data.Item, ignorePropertyExpression).Name;
                    ignorePropertyNames.Add(ignorePropertyName);
                }
            }

            foreach (var property in properties)
            {
                var ignoreProperty = ignorePropertyNames.SingleOrDefault(x => x.Equals(property.Value.Name, StringComparison.CurrentCultureIgnoreCase));
                if (ignoreProperty != null)
                {
                    continue;
                }

                var propertyType = ObjectReflectionHelper.GetPropertyType(property.Value);

                var propertyValue = ObjectReflectionHelper.GetPropertyValue(_data.Item, property.Value);
                ColumnAction(property.Value.Name, propertyValue, propertyType, DataTypes.Object, 0);
            }
        }
Beispiel #4
0
        private void SetPropertyValue(DataReaderField field, PropertyInfo property, object item, object value)
        {
            try
            {
                if (value == DBNull.Value)
                {
                    if (ObjectReflectionHelper.IsNullable(property))
                    {
                        value = null;
                    }
                    else
                    {
                        value = ObjectReflectionHelper.GetDefault(property.PropertyType);
                    }
                }
                else
                {
                    var propertyType = ObjectReflectionHelper.GetPropertyType(property);

                    if (propertyType != field.Type)
                    {
                        if (propertyType.IsEnum)
                        {
                            if (field.Type == typeof(string))
                            {
                                value = Enum.Parse(propertyType, (string)value, true);
                            }
                            else
                            {
                                value = Enum.ToObject(propertyType, value);
                            }
                        }
                        else if (!ObjectReflectionHelper.IsBasicClrType(propertyType))
                        {
                            return;
                        }
                        else if (propertyType == typeof(string))
                        {
                            value = value.ToString();
                        }
                        else
                        {
                            value = Convert.ChangeType(value, property.PropertyType);
                        }
                    }
                }

                property.SetValue(item, value, null);
            }
            catch (Exception exception)
            {
                throw new FluentDataException("Could not map: " + property.Name, exception);
            }
        }
Beispiel #5
0
        public IDbCommand Parameter(string name, object value, DataTypes parameterType = DataTypes.Object, ParameterDirection direction = ParameterDirection.Input, int size = 0)
        {
            if (ObjectReflectionHelper.IsList(value))
            {
                AddListParameterToInnerCommand(name, value);
            }
            else
            {
                AddParameterToInnerCommand(name, value, parameterType, direction, size);
            }

            return(this);
        }
Beispiel #6
0
        private object GetOrCreateInstance(object item, PropertyInfo property)
        {
            object instance = ObjectReflectionHelper.GetPropertyValue(item, property);

            if (instance == null)
            {
                instance = _dbCommandData.Context.Data.EntityFactory.Create(property.PropertyType);

                property.SetValue(item, instance, null);
            }

            return(instance);
        }
 public QueryHandler(DbCommandData data)
 {
     _data = data;
     if (typeof(TEntity) == typeof(object) || typeof(TEntity) == typeof(ExpandoObject))
     {
         _typeHandler = new QueryDynamicHandler <TEntity>(data);
     }
     else if (typeof(TEntity) == typeof(DataTable))
     {
         _typeHandler = new QueryDataTableHandler <TEntity>(data);
     }
     else if (ObjectReflectionHelper.IsCustomEntity <TEntity>())
     {
         _typeHandler = new QueryCustomEntityHandler <TEntity>(data);
     }
     else
     {
         _typeHandler = new QueryScalarHandler <TEntity>(data);
     }
 }
Beispiel #8
0
        private bool HandleComplexField(object item, DataReaderField field, object value)
        {
            string propertyName = null;

            for (var level = 0; level <= field.NestedLevels; level++)
            {
                if (string.IsNullOrEmpty(propertyName))
                {
                    propertyName = field.GetNestedName(level);
                }
                else
                {
                    propertyName += "_" + field.GetNestedName(level);
                }

                PropertyInfo property   = null;
                var          properties = ObjectReflectionHelper.GetProperties(item.GetType());
                if (properties.TryGetValue(propertyName, out property))
                {
                    if (level == field.NestedLevels)
                    {
                        SetPropertyValue(field, property, item, value);
                        return(true);
                    }
                    else
                    {
                        item = GetOrCreateInstance(item, property);
                        if (item == null)
                        {
                            return(false);
                        }
                        propertyName = null;
                    }
                }
            }

            return(false);
        }