internal bool ParseXamlDocument(TextReader reader, string desiredRule) { Microsoft.Build.Shared.ErrorUtilities.VerifyThrowArgumentNull(reader, "reader"); Microsoft.Build.Shared.ErrorUtilities.VerifyThrowArgumentLength(desiredRule, "desiredRule"); object obj2 = XamlServices.Load(reader); if (obj2 == null) { return(false); } ProjectSchemaDefinitions definitions = obj2 as ProjectSchemaDefinitions; if (definitions == null) { throw new XamlParseException(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("Xaml.InvalidRootObject", new object[0])); } foreach (IProjectSchemaNode node in definitions.Nodes) { Rule rule = node as Rule; if ((rule != null) && string.Equals(rule.Name, desiredRule, StringComparison.OrdinalIgnoreCase)) { return(this.ParseXamlDocument(rule)); } } throw new XamlParseException(Microsoft.Build.Shared.ResourceUtilities.FormatResourceString("Xaml.RuleNotFound", new object[] { desiredRule })); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static Rule LoadXamlRule(string filepath) { if (filepath == null) { throw new FileNotFoundException(nameof(filepath), filepath); } // // Allow for the potential to load properties through XAML files with a 'ProjectSchemaDefinitions' root node. // var xmlRootNode = XamlServices.Load(filepath); if (xmlRootNode == null) { return(null); } if (xmlRootNode.GetType() == typeof(ProjectSchemaDefinitions)) { ProjectSchemaDefinitions projectSchemaDefs = (ProjectSchemaDefinitions)xmlRootNode; return((Rule)projectSchemaDefs.Nodes [0]); } return((Rule)xmlRootNode); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public XamlParser(string path) { // // Allow for the potential to load properties through XAML files with a 'ProjectSchemaDefinitions' root node. // object xmlRootNode = XamlServices.Load(path); if (xmlRootNode.GetType() == typeof(ProjectSchemaDefinitions)) { ProjectSchemaDefinitions projectSchemaDefs = (ProjectSchemaDefinitions)xmlRootNode; m_parsedBuildRule = (Rule)projectSchemaDefs.Nodes [0]; } else { m_parsedBuildRule = (Rule)xmlRootNode; } ToolProperties = new Dictionary <string, PropertyWrapper> (); foreach (var prop in m_parsedBuildRule.Properties) { ToolProperties.Add(prop.Name, new PropertyWrapper(prop.GetType(), prop)); } m_typeFunctionMap = new Dictionary <Type, Action <CommandLineBuilder, BaseProperty, string> > { { typeof(StringListProperty), GenerateArgumentStringList }, { typeof(StringProperty), GenerateArgumentString }, { typeof(IntProperty), GenerateArgumentInt }, { typeof(BoolProperty), GenerateArgumentBool }, { typeof(EnumProperty), GenerateArgumentEnum } }; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static Rule ParseXamlRule(string xaml) { var xmlRootNode = XamlServices.Parse(xaml); if (xmlRootNode.GetType() == typeof(ProjectSchemaDefinitions)) { ProjectSchemaDefinitions projectSchemaDefs = (ProjectSchemaDefinitions)xmlRootNode; return(projectSchemaDefs.Nodes[0] as Rule); } return(xmlRootNode as Rule); }