예제 #1
0
        private static (List <IFormatter> fieldFormatters, List <IFormatter> tagFormatters) CreateFormatters(Type type,
                                                                                                             CustomDict customFieldFormatters, CustomDict customTagFormatters)
        {
            var fieldFormatters = new List <IFormatter>();
            var tagFormatters   = new List <IFormatter>();

            foreach (var property in type.GetProperties().Where(p => p.CanRead))
            {
                if (CheckCustomFormatters(customFieldFormatters, customTagFormatters, property, fieldFormatters, tagFormatters))
                {
                    continue;
                }

                if (FieldFormatter.IsFieldType(property.PropertyType))
                {
                    var formatter = FieldFormatter.TryCreate(property);
                    if (formatter != null)
                    {
                        fieldFormatters.Add(formatter);
                    }
                }
                else if (TagFormatter.IsTagType(property.PropertyType))
                {
                    var tagFormatter = TagFormatter.TryCreate(property);
                    if (tagFormatter != null)
                    {
                        tagFormatters.Add(tagFormatter);
                    }
                }
            }

            return(fieldFormatters, tagFormatters);
        }
예제 #2
0
        private static (List <IFormatter> fieldFormatters, List <IFormatter> tagFormatters) CreateFormatters(Type type,
                                                                                                             DiagnosticListenerOptions options)
        {
            var fieldFormatters = new List <IFormatter>();
            var tagFormatters   = new List <IFormatter>();

            foreach (var property in type.GetProperties().Where(p => p.CanRead))
            {
                if (CheckCustomFormatters(options.CustomFieldFormatters, options.CustomTagFormatters, property, fieldFormatters, tagFormatters))
                {
                    continue;
                }

                if (FieldFormatter.IsFieldType(property.PropertyType))
                {
                    var formatter = FieldFormatter.TryCreate(property, options.FieldNameFormatter ?? NameFixer.Identity);
                    if (formatter != null)
                    {
                        fieldFormatters.Add(formatter);
                    }
                }
                else if (TagFormatter.IsTagType(property.PropertyType))
                {
                    var tagFormatter = TagFormatter.TryCreate(property, options.TagNameFormatter ?? NameFixer.Identity);
                    if (tagFormatter != null)
                    {
                        tagFormatters.Add(tagFormatter);
                    }
                }
            }

            return(fieldFormatters, tagFormatters);
        }