private IPartsCatalogue CreateFakeCatalogue(Dictionary <SourceAnalyzer, List <StyleCopRule> > analyzerRules)
        {
            IPartCatalogueFactory factory = new FlyweightPartFactory();

            PartCatalogueAssembly assembly = new PartCatalogueAssembly(AssemblyNameInfo.Create("StyleCopHighlightings", null), null);

            List <PartCatalogueAttribute> assemblyAttributes             = new List <PartCatalogueAttribute>();
            List <PartCatalogueAttribute> configurableSeverityAttributes = new List <PartCatalogueAttribute>();

            foreach (KeyValuePair <SourceAnalyzer, List <StyleCopRule> > analyzerRule in analyzerRules)
            {
                string analyzerName = analyzerRule.Key.Name;
                string groupName    = string.Format(GroupTitleTemplate, analyzerName);

                var groupAttribute = new RegisterConfigurableHighlightingsGroupAttribute(groupName, groupName);
                assemblyAttributes.Add(CreatePartAttribute(groupAttribute, factory));

                foreach (StyleCopRule rule in analyzerRule.Value)
                {
                    string ruleName    = rule.RuleID + ": " + SplitCamelCase(rule.Name);
                    string highlightID = GetHighlightID(rule.RuleID);

                    RegisterConfigurableSeverityAttribute itemAttribute =
                        new RegisterConfigurableSeverityAttribute(
                            highlightID,
                            null,
                            groupName,
                            ruleName,
                            rule.Description,
                            Severity.WARNING,
                            false);
                    assemblyAttributes.Add(CreatePartAttribute(itemAttribute, factory));

                    ConfigurableSeverityHighlightingAttribute configurableSeverityHighlightingAttribute = new ConfigurableSeverityHighlightingAttribute(highlightID, "CSHARP");
                    configurableSeverityAttributes.Add(PartHelpers.CreatePartAttribute(configurableSeverityHighlightingAttribute, factory));
                }
            }

            assembly.AssignAttributes(assemblyAttributes);

            PartCatalogueType fakeConfigurableSeverityHighlight;

            factory.GetOrCreateType("Fake", PartCatalogTypeKind.Regular, assembly, out fakeConfigurableSeverityHighlight);
            fakeConfigurableSeverityHighlight.AssignRecursiveTypes(new PartCatalogueType.RecursiveData
            {
                Attributes = configurableSeverityAttributes
            });

            IList <PartCatalogueAssembly> assemblies = new List <PartCatalogueAssembly>()
            {
                assembly
            };

            IList <PartCatalogueType> parts = new List <PartCatalogueType>();

            parts.Add(fakeConfigurableSeverityHighlight);
            return(new PartsCatalogue(parts, assemblies));
        }
        private static PartCatalogueAttribute CreatePartAttribute(Attribute attribute, IPartCatalogueFactory factory)
        {
            // OK, this is getting out of hand. It seemed like a good idea to replace
            // reflection with a fake catalogue, but ReSharper 10 has changed things.
            // Implementing your own catalogue is non-trivial, and the wrapper for
            // legacy catalogues has issues with attribute properties (including ctor
            // args). It expects a string instance to be represented with a StringSource,
            // and tries to unbox an enum directly into a ulong, which fails. We can work
            // around these by replacing the actual value in the properties with one that
            // will work. But it also tries to unbox a bool into a ulong, which also fails,
            // and we can't work around that (it asserts that the value in the property is
            // also a bool). So, we totally fudge it. It just so happens that the values
            // we want to use are false, and HighlightSettingsManagerImpl will handle
            // missing values nicely, defaulting to false. So, rip em out.
            // Perhaps reflection was the better idea... (well, strictly speaking not having
            // "dynamically" loaded highlightings is a better idea!)
            var originalPartAttribute = PartHelpers.CreatePartAttribute(attribute, factory);
            var newProperties         = from p in originalPartAttribute.GetProperties()
                                        where !(p.Value is bool && (bool)p.Value == false)
                                        select new PartCatalogueAttributeProperty(p.Name, WrapValue(p.Value), p.Disposition);

            return(new PartCatalogueAttribute(originalPartAttribute.Type, newProperties, originalPartAttribute.ConstructorFormalParameterTypes));
        }