public GridColumnAttribute GetAnnotationForColumn <T>(PropertyInfo pi)
        {
            pi = GetMetadataProperty <T>(pi);

            var gridAttr = pi.GetAttribute <GridColumnAttribute>();

            GridColumnAttribute dataAnnotationAttr = gridAttr;

            DataAnnotationsOptions dataAnnotations = ExtractDataAnnotations(pi);

            if (dataAnnotations != null)
            {
                if (gridAttr == null)
                {
                    dataAnnotationAttr = new GridColumnAttribute
                    {
                        Title         = dataAnnotations.DisplayName,
                        FilterEnabled = dataAnnotations.FilterEnabled ?? false,
                        Format        = dataAnnotations.Format
                    };
                }
                else
                {
                    dataAnnotationAttr.Title         = string.IsNullOrEmpty(gridAttr.Title) ? dataAnnotations.DisplayName : gridAttr.Title;
                    dataAnnotationAttr.FilterEnabled = dataAnnotations.FilterEnabled ?? gridAttr.FilterEnabled;
                    dataAnnotationAttr.Format        = string.IsNullOrEmpty(gridAttr.Format) ? dataAnnotations.Format : gridAttr.Format;
                }
            }
            return(dataAnnotationAttr);
        }
Exemplo n.º 2
0
        public GridHiddenColumnAttribute GetAnnotationForHiddenColumn <T>(PropertyInfo pi)
        {
            pi = GetMetadataProperty <T>(pi);

            var gridAttr = pi.GetAttribute <GridHiddenColumnAttribute>();

            if (gridAttr != null)
            {
                return(gridAttr);
            }

            GridHiddenColumnAttribute dataAnnotationAttr = null;

            DataAnnotationsOptions dataAnnotations = ExtractDataAnnotations(pi);

            if (dataAnnotations != null)
            {
                dataAnnotationAttr = new GridHiddenColumnAttribute
                {
                    Format = dataAnnotations.Format,
                    Key    = dataAnnotations.Key
                };
            }
            return(dataAnnotationAttr);
        }
Exemplo n.º 3
0
        private DataAnnotationsOptions ExtractDataAnnotations(PropertyInfo pi)
        {
            DataAnnotationsOptions result = null;
            var displayAttr = pi.GetAttribute <DisplayAttribute>();

            if (displayAttr != null)
            {
                result               = new DataAnnotationsOptions();
                result.DisplayName   = displayAttr.GetName();
                result.FilterEnabled = displayAttr.GetAutoGenerateFilter();
            }
            else
            {
                var displayNameAttr = pi.GetAttribute <DisplayNameAttribute>();
                if (displayNameAttr != null)
                {
                    result             = new DataAnnotationsOptions();
                    result.DisplayName = displayNameAttr.DisplayName;
                }
            }
            var displayFormatAttr = pi.GetAttribute <DisplayFormatAttribute>();

            if (displayFormatAttr != null)
            {
                if (result == null)
                {
                    result = new DataAnnotationsOptions();
                }
                result.Format = displayFormatAttr.DataFormatString;
            }
            return(result);
        }
Exemplo n.º 4
0
        public GridColumnAttribute GetAnnotationForColumn <T>(PropertyInfo pi)
        {
            pi = GetMetadataProperty <T>(pi);

            var gridAttr = pi.GetAttribute <GridColumnAttribute>();

            if (gridAttr != null)
            {
                return(gridAttr);
            }

            GridColumnAttribute dataAnnotationAttr = null;

            DataAnnotationsOptions dataAnnotations = ExtractDataAnnotations(pi);

            if (dataAnnotations != null)
            {
                dataAnnotationAttr = new GridColumnAttribute
                {
                    Title         = dataAnnotations.DisplayName,
                    FilterEnabled = dataAnnotations.FilterEnabled ?? false,
                    Format        = dataAnnotations.Format
                };
            }
            return(dataAnnotationAttr);
        }