internal static bool TryParse(ParseResult result, AttributesHelper attributes, string attributeName, out bool answer) { XAttribute attr = attributes.PopAttribute(attributeName); // If it has the attribute if (attr != null) { // And the attribute has a value if (attr.Value != null) { // If it's a bool if (bool.TryParse(attr.Value, out answer)) { return(true); } // Otherwise warning about not being double result.AddWarning($@"{attributeName} only accepts boolean values, not ""{attr.Value}""", GetErrorPositionInfo(attr)); } // Attribute doesn't have a value else { result.AddWarning($@"Attribute {attributeName} has no value specified", GetErrorPositionInfo(attr)); } } // Attribute isn't found, no warning answer = default(bool); return(false); }
internal static bool TryParseEnum <TEnum>(ParseResult result, AttributesHelper attributes, string attributeName, out TEnum answer, bool caseSensitive = true) where TEnum : struct { XAttribute attr = attributes.PopAttribute(attributeName, caseSensitive); // If it has the attribute if (attr != null) { // And the attribute has a value if (attr.Value != null) { if (TryParseEnum(attr.Value, out answer)) { return(true); } // Couldn't find matching enum result.AddWarning($@"Unknown value ""{attr.Value}"" on {attributeName} attribute", GetErrorPositionInfo(attr)); } // Attribute doesn't have a value else { result.AddWarning($@"Attribute {attributeName} has no value specified", GetErrorPositionInfo(attr)); } } // Attribute isn't found, no warning answer = default(TEnum); return(false); }
private void ParseTileHelper(ParseResult result, XContainer parentNode, FeatureSet supportedFeatures) { XElement node = parentNode.FirstElementOrDefault("tile"); if (node == null) { result.AddError("tile element was not found", ErrorPositionInfo.Default); return; } if (!EnsureNodeOnlyHasElementsAsChildren(result, node)) { return; } result.Tile = new Model.Tile(supportedFeatures); AttributesHelper attributes = new AttributesHelper(node.Attributes()); // tile doesn't have any attributes AddWarningsForUnknownAttributes(result, attributes); ParseVisual(result, result.Tile.Visual, node); }
private void ParseAdaptiveContentHelper(ParseResult result, XElement parentNode, FeatureSet supportedFeatures) { result.AdaptiveContent = new AdaptiveContainer(Model.NotificationType.AdaptiveContent, supportedFeatures); try { AttributesHelper attributes = new AttributesHelper(parentNode.Attributes()); result.AdaptiveContent.ContinueParsing(result, parentNode, attributes, parentNode.Elements(), null, false); } catch (IncompleteElementException) { } }
internal static void AddWarningsForAttributesNotSupportedByVisualizer(ParseResult result, AttributesHelper attributes, params string[] attributeNames) { foreach (string attrName in attributeNames) { XAttribute a = attributes.PopAttribute(attrName); if (a != null) { result.AddWarning($@"The attribute ""{attrName}"" is a valid attribute, but the Visualizer does not support it.", GetErrorPositionInfo(a)); } } }