Пример #1
0
        private void ConfigureRestOfProperties(Type objectType, FileExportSpecification fileExportSpecification)
        {
            // fallback formatter for anything that doesn't fit int he custom, or "global default" formatters.
            var globalDefaultFormatter = new PropertyFormatter(context =>
                                                                {
                                                                    if (context.ItemValue == null)
                                                                    {
                                                                        return string.Empty;
                                                                    }
                                                                    return context.ItemValue.ToString();
                                                                });
            var properties = objectType.GetProperties();

            for (int i = 0; i < properties.Length; i++)
            {
                var propertyInfo = properties[i];
                var propertyName = propertyInfo.Name;

                TypeConfiguration props = fileExportSpecification.GetTypeConfiguration(objectType);

                if (!props.IsPropertyExcluded(propertyName))
                {
                    if (props.IsPropertyDefined(propertyName))
                    {
                        props.Properties[propertyName].Order = i;
                        continue;
                    }

                    var propertyType = propertyInfo.PropertyType;

                    PropertyFormatter defaultPropertyFormatter = globalDefaultFormatter;

                    if (DefaultPropertyFormatters.ContainsKey(propertyType))
                    {
                        defaultPropertyFormatter = DefaultPropertyFormatters[propertyType];
                    }

                    if (fileExportSpecification.DefaultPropertyFormatters.ContainsKey(propertyType))
                    {
                        defaultPropertyFormatter = fileExportSpecification.DefaultPropertyFormatters[propertyType];
                    }

                    // If there's a default
                    if (props.DefaultTypeFormatters.ContainsKey(propertyType))
                    {
                        defaultPropertyFormatter = props.DefaultTypeFormatters[propertyType];
                    }

                    var property = new Property(objectType, propertyName, defaultPropertyFormatter, fileExportSpecification.DefaultHeaderFormatter, i);

                    props.AddProperty(property);
                }
            }
        }
Пример #2
0
        public FileExportSpecification CreateSpec(IEnumerable<Type> supportedTypes, Action<FileExportSpecification> configuration)
        {
            var fileExportSpecification = new FileExportSpecification(supportedTypes, ",", Environment.NewLine);
            configuration(fileExportSpecification);

            foreach (var supportedType in supportedTypes)
            {
                if (!fileExportSpecification.SkipNonConfiguredProperties)
                {
                    ConfigureRestOfProperties(supportedType, fileExportSpecification);
                }
            }
            return fileExportSpecification;
        }