Example #1
0
        public static Table <T> ToTable <T>(this IEnumerable <T> values, bool showHeader = true, string sheetName = null)
        {
            var table = new Table <T>();

            table.DataSource = values;
            table.ShowHeader = showHeader;
            table.Title      = sheetName ?? ConvertUtilities.Decamelize(typeof(T).Name);
            return(table);
        }
Example #2
0
        public static Metadata Create(MemberInfo memberInfo)
        {
            if (memberInfo == null)
            {
                throw new ArgumentNullException("memberInfo");
            }

            Metadata metadata = new Metadata();

            // Name
            metadata.Name = memberInfo.Name;

            // DisplayAttribute
            DisplayAttribute displayAttribute = memberInfo.GetCustomAttribute <DisplayAttribute>();

            if (displayAttribute != null)
            {
                metadata.DisplayName = displayAttribute.GetName();
                metadata.ShortName   = displayAttribute.GetShortName();
                metadata.GroupName   = displayAttribute.GetGroupName();
                metadata.Description = displayAttribute.GetDescription();

                int?order = displayAttribute.GetOrder();
                if (order != null)
                {
                    metadata.Order = order.Value;
                }
            }

            if (metadata.DisplayName == null)
            {
                metadata.DisplayName = ConvertUtilities.Decamelize(metadata.Name);
            }

            // DataType
            DataTypeAttribute dataTypeAttribute = memberInfo.GetCustomAttribute <DataTypeAttribute>();

            if (dataTypeAttribute != null)
            {
                metadata.DataType = dataTypeAttribute.GetDataTypeName();
                Fill(metadata, dataTypeAttribute.DisplayFormat);
            }
            if (metadata.DataType == null)
            {
                PropertyInfo pi = memberInfo as PropertyInfo;
                if (pi != null)
                {
                    metadata.DataType = pi.PropertyType.AssemblyQualifiedName;
                }
                else
                {
                    FieldInfo fi = memberInfo as FieldInfo;
                    if (fi != null)
                    {
                        metadata.DataType = fi.FieldType.AssemblyQualifiedName;
                    }
                }
            }

            // DisplayFormat
            DisplayFormatAttribute displayFormatAttribute = memberInfo.GetCustomAttribute <DisplayFormatAttribute>();

            if (displayFormatAttribute != null)
            {
                Fill(metadata, displayFormatAttribute);
            }

            // ScaffoldColumnAttribute
            ScaffoldColumnAttribute scaffoldColumnAttribute = memberInfo.GetCustomAttribute <ScaffoldColumnAttribute>();

            if (scaffoldColumnAttribute != null)
            {
                metadata.Hidden = scaffoldColumnAttribute.Scaffold;
            }

            return(metadata);
        }