Пример #1
0
        private static SimpleBindPropertyInfo HandleColumnClassTypeProperty(PropertyInfo propertyInfo)
        {
            var columnInfo = new SimpleBindPropertyInfo();

            // get link
            var showLinkedAttribute = propertyInfo.GetCustomAttributes(false)
                                      .FirstOrDefault(item => item is ShowLinkedAttribute) as ShowLinkedAttribute;

            if (showLinkedAttribute != null && !string.IsNullOrEmpty(showLinkedAttribute.PropertyName))
            {
                // check does property exists
                var linkedProperty = propertyInfo.PropertyType.GetProperty(showLinkedAttribute.PropertyName);
                if (linkedProperty != null)
                {
                    columnInfo.Name     = propertyInfo.Name + "." + linkedProperty.Name;
                    columnInfo.DataType = linkedProperty.PropertyType;
                    return(columnInfo);
                }
            }

            // default values
            columnInfo.Name     = propertyInfo.Name;
            columnInfo.DataType = propertyInfo.PropertyType;

            return(columnInfo);
        }
Пример #2
0
        public static IEnumerable <SimpleBindPropertyInfo> GenerateColumnsInfo <T>()
        {
            var columnsInfo = new List <SimpleBindPropertyInfo>();

            foreach (var propertyInfo in typeof(T).GetProperties())
            {
                // check should be shown this property
                if (!ShowProperty(propertyInfo) || !ShowInDataGridProperty(propertyInfo))
                {
                    continue;
                }


                // create column info object
                SimpleBindPropertyInfo columnInfo = null;

                if (propertyInfo.PropertyType.IsClass)
                {
                    columnInfo = HandleColumnClassTypeProperty(propertyInfo);
                }
                else
                {
                    columnInfo = new SimpleBindPropertyInfo
                    {
                        Name     = propertyInfo.Name,
                        DataType = propertyInfo.PropertyType
                    };
                }

                // format for date
                columnInfo.Format = propertyInfo.PropertyType == typeof(DateTime) || propertyInfo.PropertyType == typeof(DateTime?)
                    ? AppSettings.DateFormat
                    : GetPropertyFormat(propertyInfo);

                // check IsReadOnly
                columnInfo.IsReadOnly = IsReadOnlyProperty(propertyInfo);
                // set header
                columnInfo.Header = GetPropertyHeader(propertyInfo);
                // set order
                columnInfo.Order = GetPropertyOrder(propertyInfo);

                // add to all columns
                columnsInfo.Add(columnInfo);
            }

            return(columnsInfo.OrderBy(item => item.Order));
        }