예제 #1
0
        public static ExcelFormatter GetFormat(Type type)
        {
            ExcelFormatter formatter;

            if (!_formatsByType.TryGetValue(type, out formatter))
            {
                if (type.IsEnum)
                {
                    formatter = new ExcelFormatter
                    {
                        SourceType   = type,
                        TargetType   = typeof(string),
                        DefaultValue = "",
                        GetValue     = x => String.Join(", ", x.Values.Select(DescriptionExtractor.GetDescription)),
                        StringFormat = null
                    };
                }
                else
                {
                    formatter = new ExcelFormatter
                    {
                        SourceType   = type,
                        TargetType   = typeof(string),
                        DefaultValue = "",
                        GetValue     = x => "#FORMATERROR#",
                        StringFormat = null
                    };
                }

                _formatsByType.Add(type, formatter);
            }

            return(formatter);
        }
예제 #2
0
        public static ExcelFormatter Add <TSource, TTarget>(Func <TSource[], TTarget> getValue, TTarget defaultValue, string stringFormat)
        {
            ExcelFormatter format = new ExcelFormatter
            {
                SourceType   = typeof(TSource),
                TargetType   = typeof(TTarget),
                DefaultValue = defaultValue,
                StringFormat = stringFormat,
                GetValue     = x => x == null ? defaultValue : getValue(x.Values.OfType <TSource>().ToArray())
            };

            _formatsByType.Add(format.SourceType, format);
            return(format);
        }