public static ImmutableDictionary <string, string> GetClassificationNameMap()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // This results in a dictionary where the keys are font/color item
            // names and the values are VS editor format classification names.

            var builder = ImmutableDictionary.CreateBuilder <string, string>();
            var efds    = VSServiceHelpers.GetMefExports <EditorFormatDefinition>().ToArray();

            foreach (var efd in efds)
            {
                var type = efd.GetType();
                var uv   = type.GetCustomAttribute <UserVisibleAttribute>();
                if (uv?.UserVisible != true)
                {
                    continue;
                }
                var name = type.GetCustomAttribute <NameAttribute>()?.Name;
                var ctns = type.GetCustomAttribute <ClassificationTypeAttribute>()?.ClassificationTypeNames;
                if (string.IsNullOrEmpty(name))
                {
                    continue;
                }
                builder.Add(name, ctns ?? name);
            }

            return(builder.ToImmutable());
        }
        static ClassificationMap()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var builder = ImmutableDictionary.CreateBuilder <string, string>();
            var efds    = VSServiceHelpers.GetMefExports <EditorFormatDefinition>().ToArray();

            foreach (var efd in efds)
            {
                var type = efd.GetType();
                var uv   = type.GetCustomAttribute <UserVisibleAttribute>();
                if (uv?.UserVisible != true)
                {
                    continue;
                }
                var name = type.GetCustomAttribute <NameAttribute>()?.Name;
                var ctns = type.GetCustomAttribute <ClassificationTypeAttribute>()?.ClassificationTypeNames;
                if (string.IsNullOrEmpty(name))
                {
                    continue;
                }
                builder.Add(name, ctns ?? name);
            }

            itemNameToClassification = builder.ToImmutable();
        }
Ejemplo n.º 3
0
        public static ImmutableDictionary <string, string> GetClassificationNameMap()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            return(VSServiceHelpers.GetMefExports <EditorFormatDefinition>()
                   .Select(definition => definition.GetType())
                   .Where(type => type.GetCustomAttribute <UserVisibleAttribute>()?.UserVisible == true)
                   .Select(type => (type.GetCustomAttribute <NameAttribute>()?.Name, type.GetCustomAttribute <ClassificationTypeAttribute>()?.ClassificationTypeNames))
                   .Where(names => !string.IsNullOrEmpty(names.Name))
                   .ToImmutableDictionary(t => t.Name, t => t.ClassificationTypeNames ?? t.Name));
        }