Esempio n. 1
0
        private void method_2(DataReaderField dataReaderField_0, PropertyInfo propertyInfo_0, object object_0, object object_1)
        {
            try
            {
                if (object_1 == DBNull.Value)
                {
                    object_1 = ((!ReflectionHelper.IsNullable(propertyInfo_0)) ? ReflectionHelper.GetDefault(propertyInfo_0.PropertyType) : null);
                    goto IL_00b4;
                }
                Type propertyType = ReflectionHelper.GetPropertyType(propertyInfo_0);
                if (!(propertyType != dataReaderField_0.Type))
                {
                    goto IL_00b4;
                }
                if (propertyType.IsEnum)
                {
                    object_1 = ((!(dataReaderField_0.Type == typeof(string))) ? Enum.ToObject(propertyType, object_1) : Enum.Parse(propertyType, (string)object_1, true));
                    goto IL_00b4;
                }
                if (ReflectionHelper.IsBasicClrType(propertyType))
                {
                    object_1 = ((!(propertyType == typeof(string))) ? Convert.ChangeType(object_1, propertyInfo_0.PropertyType) : object_1.ToString());
                    goto IL_00b4;
                }
                goto end_IL_0001;
IL_00b4:
                propertyInfo_0.SetValue(object_0, object_1, null);
                end_IL_0001 :;
            }
            catch (Exception innerException)
            {
                throw new FluentDataException("Could not map: " + propertyInfo_0.Name, innerException);
            }
        }
Esempio n. 2
0
        private bool method_0(object object_0, DataReaderField dataReaderField_0, object object_1)
        {
            string text = null;
            int    num  = 0;

            while (true)
            {
                if (num > dataReaderField_0.NestedLevels)
                {
                    return(false);
                }
                text = ((!string.IsNullOrEmpty(text)) ? (text + "_" + dataReaderField_0.GetNestedName(num)) : dataReaderField_0.GetNestedName(num));
                PropertyInfo value = null;
                Dictionary <string, PropertyInfo> properties = ReflectionHelper.GetProperties(object_0.GetType());
                if (properties.TryGetValue(text, out value))
                {
                    if (num == dataReaderField_0.NestedLevels)
                    {
                        method_2(dataReaderField_0, value, object_0, object_1);
                        return(true);
                    }
                    object_0 = method_1(object_0, value);
                    if (object_0 == null)
                    {
                        break;
                    }
                    text = null;
                }
                num++;
            }
            return(false);
        }
Esempio n. 3
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 = ReflectionHelper.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;
		}
Esempio n. 4
0
        private void SetPropertyValue(DataReaderField field, PropertyInfo property, object item, object value)
        {
            try
            {
                if (value == DBNull.Value)
                {
                    if (ReflectionHelper.IsNullable(property))
                    {
                        value = null;
                    }
                    else
                    {
                        value = ReflectionHelper.GetDefault(property.PropertyType);
                    }
                }
                else
                {
                    var propertyType = ReflectionHelper.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 (!ReflectionHelper.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);
            }
        }
Esempio n. 5
0
        internal static List <DataReaderField> GetDataReaderFields(System.Data.IDataReader reader)
        {
            List <DataReaderField> list = new List <DataReaderField>();

            for (int i = 0; i < reader.FieldCount; i++)
            {
                DataReaderField column = new DataReaderField(i, reader.GetName(i), reader.GetFieldType(i));
                if (list.SingleOrDefault((DataReaderField x) => x.LowerName == column.LowerName) == null)
                {
                    list.Add(column);
                }
            }
            return(list);
        }
		internal static List<DataReaderField> GetDataReaderFields(System.Data.IDataReader reader)
		{
			var columns = new List<DataReaderField>();

			for (var i = 0; i < reader.FieldCount; i++)
			{
				var column = new DataReaderField(i, reader.GetName(i), reader.GetFieldType(i));

				if (columns.SingleOrDefault(x => x.LowerName == column.LowerName) == null)
					columns.Add(column);
			}

			return columns;
		}
        internal static List <DataReaderField> GetDataReaderFields(IDataReader reader)
        {
            var columns = new List <DataReaderField>();

            for (var i = 0; i < reader.FieldCount; i++)
            {
                var column = new DataReaderField(i, reader.GetName(i), reader.GetFieldType(i));

                if (columns.SingleOrDefault(x => x.LowerName == column.LowerName) == null)
                {
                    columns.Add(column);
                }
            }

            return(columns);
        }
Esempio n. 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 = ReflectionHelper.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);
        }
Esempio n. 9
0
		private void SetPropertyValue(DataReaderField field, PropertyInfo property, object item, object value)
		{
			try
			{
				if (value == DBNull.Value)
				{
					if (ReflectionHelper.IsNullable(property))
						value = null;
					else
						value = ReflectionHelper.GetDefault(property.PropertyType);
				}
				else
				{
					var propertyType = ReflectionHelper.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 (!ReflectionHelper.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);
			}
		}