示例#1
0
        public static DataTable GetDataTable(bool shapeColumnNames)
        {
            DataTable result = new DataTable();
            Type      t      = typeof(E);

            foreach (PropertyInfo p in t.GetProperties())
            {
                Type propertyType = p.PropertyType;
                if (p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    propertyType = p.PropertyType.GetGenericArguments()[0];
                }
                if (propertyType == typeof(Boolean))
                {
                    propertyType = typeof(String);
                }
                string columnName = shapeColumnNames ? DataShaper.FormatEntityColumnName(p.Name) : p.Name;
                result.Columns.Add(new DataColumn(columnName)
                {
                    Caption  = p.Name,
                    DataType = propertyType
                });
            }
            return(result);
        }
示例#2
0
        public static DataRow PopulateDataRow(E entity, DataRow row, bool shapePropertyNames)
        {
            Type entityType = typeof(E);

            foreach (PropertyInfo p in entityType.GetProperties())
            {
                object propertyValue = GetPropertyValue(p.Name, entity, true);
                string propertyName  = shapePropertyNames ? DataShaper.FormatEntityColumnName(p.Name) : p.Name;
                row[propertyName] = propertyValue;
            }
            return(row);
        }
示例#3
0
        public static string GetPropertyName <TProp>(Expression <Func <E, TProp> > expression, bool shapePropertyName)
        {
            var body = expression.Body as MemberExpression;

            if (body == null)
            {
                throw new ArgumentException("'expression' should be a member expression");
            }
            if (shapePropertyName)
            {
                return(DataShaper.FormatEntityColumnName(body.Member.Name));
            }
            return(body.Member.Name);
        }