/// <summary> /// Gets the rules. /// </summary> /// <param name="analyzer"> /// The analyzer. /// </param> /// <returns> /// A list of all the rules for the <see cref="SourceAnalyzer"/>. /// </returns> private static List <StyleCopRule> GetRules(SourceAnalyzer analyzer) { XmlDocument xmlDocument = StyleCopCore.LoadAddInResourceXml(analyzer.GetType(), null); List <StyleCopRule> xmlDefinedRules = GetRulesFromXml(xmlDocument); return(xmlDefinedRules); }
/// <summary> /// Reads parser configuration xml and initializes the dictionary 'projectFullPaths' based on the information in it. /// </summary> /// <remarks> /// Format of the xml that must be found in "SourceParser" tag in the Parser xml: /// <![CDATA[ /// <VsProjectLocation> /// <!-- PropertyName is the property name in the EnvDTE.Project's properties collection that specifies the full path to the directory of the project file. --> /// <PropertyName>FullPath</PropertyName> /// <!-- ProjectKind is the guid that identifies the project kind, or in other words the language type C#/C++ etc. /// The C# language kind is defined by prjKindCSharpProject in VSLangProj.DLL. /// The VB language kind is defined by prjKindVBProject in VSLangProj.DLL. /// Also look at dte.idl for various vsProjectKind* constants that could be returned by other projects. /// --> /// <ProjectKind>FAE04EC0-301F-11D3-BF4B-00C04F79EFBC</ProjectKind> /// </VsProjectLocation> /// ]]> /// </remarks> private void RetrieveParserConfiguration() { Debug.Assert(this.core != null, "core has not been initialized"); Debug.Assert(this.core.Parsers != null, "core parsers has not been initialized."); foreach (SourceParser parser in this.core.Parsers) { XmlDocument document = StyleCopCore.LoadAddInResourceXml(parser.GetType(), null); // Using plenty of exceptions with regards to the information drawn from the configuration xml. // An alternative would of course be to validate against a schema. XmlNodeList projectTypeNodes = document.DocumentElement.SelectNodes("VsProjectTypes/VsProjectType"); if (projectTypeNodes != null) { foreach (XmlNode projectTypeNode in projectTypeNodes) { // Find the ProjectKind attribute XmlNode projectKindNode = projectTypeNode.Attributes["ProjectKind"]; if (projectKindNode == null) { string errorMessage = Strings.MalFormedVsProjectLocationNode; errorMessage = string.Format(CultureInfo.CurrentCulture, errorMessage, Strings.NoProjectKindNodeFound); throw new InvalidDataException(errorMessage); } // Determine the project kind string projectKind = projectKindNode.InnerText.Trim(); if (string.IsNullOrEmpty(projectKind)) { string errorMessage = Strings.MalFormedVsProjectLocationNode; string subMessage = string.Format(CultureInfo.CurrentCulture, Strings.EmptyChildNode, "ProjectKind"); errorMessage = string.Format(CultureInfo.CurrentCulture, errorMessage, subMessage); throw new InvalidDataException(errorMessage); } // Get or create the property collection for the project type. Dictionary <string, string> projectProperties = null; if (!this.projectTypes.TryGetValue(projectKind, out projectProperties)) { projectProperties = new Dictionary <string, string>(); this.projectTypes.Add(projectKind, projectProperties); } // Determine the project path property name value string projectPathPropertyName = null; XmlNode projectPathPropertyNameNode = projectTypeNode.SelectSingleNode("ProjectPathPropertyName"); if (projectPathPropertyNameNode != null) { projectPathPropertyName = projectPathPropertyNameNode.InnerText.Trim(); if (string.IsNullOrEmpty(projectPathPropertyName)) { string errorMessage = Strings.MalFormedVsProjectLocationNode; string subMessage = string.Format(CultureInfo.CurrentCulture, Strings.EmptyChildNode, "PropertyName"); errorMessage = string.Format(CultureInfo.CurrentCulture, errorMessage, subMessage); throw new InvalidDataException(errorMessage); } } string existingPropertyName = null; if (!projectProperties.TryGetValue("ProjectPath", out existingPropertyName)) { // Add the new information to the dictionary projectProperties.Add("ProjectPath", projectPathPropertyName); } else { // Allow this to succeed at runtime. Debug.Fail("A previously loaded parser already registered a property name for the Project Full Path with regards to the project kind: " + projectKind); } } } } }