/// <summary>
		/// Initializes custom analyzer based on the standard one.
		/// </summary>
		public static void InitializeCustomAnalyzer(
			StyleCopCore originalCore,
			StyleCopCore customCore,
			string originalAnalyzerId,
			SourceAnalyzer customAnalyzer)
		{
			Dictionary<string, SourceAnalyzer> originalAnalyzers = (Dictionary<string, SourceAnalyzer>)typeof(StyleCopCore).InvokeMember(
				"analyzers",
				BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField,
				null,
				originalCore,
				null);

			SourceAnalyzer originalAnalyzer = originalAnalyzers[originalAnalyzerId];

			Dictionary<string, Rule> originalRules = (Dictionary<string, Rule>)typeof(StyleCopAddIn).InvokeMember(
				"rules",
				BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField,
				null,
				originalAnalyzer,
				null);

			typeof(StyleCopAddIn).InvokeMember(
				"core",
				BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField,
				null,
				customAnalyzer,
				new object[] { customCore });

			Dictionary<string, Rule> customRules = new Dictionary<string, Rule>();
			foreach (KeyValuePair<string, Rule> pair in originalRules)
			{
				Rule originalRule = pair.Value;
				Rule customRule = (Rule)typeof(Rule).InvokeMember(
					"Rule",
					BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.CreateInstance,
					null,
					customCore,
					new object[]
					{
						originalRule.Name,
						originalRule.Namespace,
						originalRule.CheckId,
						originalRule.Context,
						originalRule.Warning,
						originalRule.Description,
						originalRule.RuleGroup,
						true,
						false
					});
				customRules[pair.Key] = customRule;
			}

			typeof(StyleCopAddIn).InvokeMember(
				"rules",
				BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField,
				null,
				customAnalyzer,
				new object[] { customRules });

			CustomCsParser customParser = new CustomCsParser();

			typeof(SourceAnalyzer).InvokeMember(
				"parser",
				BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField,
				null,
				customAnalyzer,
				new object[] { customParser });
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes custom analyzer based on the standard one.
        /// </summary>
        public static void InitializeCustomAnalyzer(
            StyleCopCore originalCore,
            StyleCopCore customCore,
            string originalAnalyzerId,
            SourceAnalyzer customAnalyzer)
        {
            Dictionary <string, SourceAnalyzer> originalAnalyzers = (Dictionary <string, SourceAnalyzer>) typeof(StyleCopCore).InvokeMember(
                "analyzers",
                BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField,
                null,
                originalCore,
                null);

            SourceAnalyzer originalAnalyzer = originalAnalyzers[originalAnalyzerId];

            Dictionary <string, Rule> originalRules = (Dictionary <string, Rule>) typeof(StyleCopAddIn).InvokeMember(
                "rules",
                BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField,
                null,
                originalAnalyzer,
                null);

            typeof(StyleCopAddIn).InvokeMember(
                "core",
                BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField,
                null,
                customAnalyzer,
                new object[] { customCore });

            Dictionary <string, Rule> customRules = new Dictionary <string, Rule>();

            foreach (KeyValuePair <string, Rule> pair in originalRules)
            {
                Rule originalRule = pair.Value;
                Rule customRule   = (Rule)typeof(Rule).InvokeMember(
                    "Rule",
                    BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.CreateInstance,
                    null,
                    customCore,
                    new object[]
                {
                    originalRule.Name,
                    originalRule.Namespace,
                    originalRule.CheckId,
                    originalRule.Context,
                    originalRule.Warning,
                    originalRule.Description,
                    originalRule.RuleGroup,
                    true,
                    false
                });
                customRules[pair.Key] = customRule;
            }

            typeof(StyleCopAddIn).InvokeMember(
                "rules",
                BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField,
                null,
                customAnalyzer,
                new object[] { customRules });

            CustomCsParser customParser = new CustomCsParser();

            typeof(SourceAnalyzer).InvokeMember(
                "parser",
                BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.SetField,
                null,
                customAnalyzer,
                new object[] { customParser });
        }