コード例 #1
0
ファイル: InstanceFactory.cs プロジェクト: zanaca/b1pp
        private static void SetPropertyValue <T>(IRecordsetReader reader, PropertyInfo property, T instance) where T : class
        {
            var propertyType = property.PropertyType;

            if (propertyType == typeof(string))
            {
                property.SetValue(instance, reader.GetString(property.Name));
            }
            else if (propertyType == typeof(DateTime))
            {
                property.SetValue(instance, reader.GetDateTime(property.Name));
            }
            else if (propertyType == typeof(int))
            {
                property.SetValue(instance, reader.GetInt(property.Name));
            }
            else if (propertyType == typeof(double))
            {
                property.SetValue(instance, reader.GetDouble(property.Name));
            }
            else if (propertyType == typeof(bool))
            {
                property.SetValue(instance, reader.GetBool(property.Name));
            }
            else if (propertyType == typeof(Id))
            {
                string value = reader.GetString(property.Name);
                property.SetValue(instance, new Id(value));
            }
        }
コード例 #2
0
ファイル: InstanceFactory.cs プロジェクト: zanaca/b1pp
        public static dynamic CreateDynamicObject(IRecordsetReader reader)
        {
            var expando = new ExpandoObject();
            var data    = (IDictionary <string, object>)expando;

            foreach (var column in reader.Columns)
            {
                if (data.ContainsKey(column.Name))
                {
                    var message = $"The column '{column.Name}' appears twice or more times. " +
                                  $"Please use different aliases for each column.";
                    throw new ArgumentException(message);
                }

                switch (column.Type)
                {
                case BoFieldTypes.db_Alpha:
                case BoFieldTypes.db_Memo:
                    data.Add(column.Name, reader.GetString(column.Name));
                    break;

                case BoFieldTypes.db_Numeric:
                    data.Add(column.Name, reader.GetInt(column.Name));
                    break;

                case BoFieldTypes.db_Date:
                    data.Add(column.Name, reader.GetDateTime(column.Name));
                    break;

                case BoFieldTypes.db_Float:
                    data.Add(column.Name, reader.GetDouble(column.Name));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(expando);
        }