private static void ReadRequiredAttribute(RequiredAttributeDescriptorBuilder builder, JObject attribute, JsonSerializer serializer) { var name = attribute[nameof(RequiredAttributeDescriptor.Name)].Value <string>(); var nameComparison = attribute[nameof(RequiredAttributeDescriptor.NameComparison)].Value <int>(); var value = attribute[nameof(RequiredAttributeDescriptor.Value)].Value <string>(); var valueComparison = attribute[nameof(RequiredAttributeDescriptor.ValueComparison)].Value <int>(); var diagnostics = attribute[nameof(RequiredAttributeDescriptor.Diagnostics)].Value <JArray>(); var metadata = attribute[nameof(RequiredAttributeDescriptor.Metadata)].Value <JObject>(); builder.Name = name; builder.NameComparisonMode = (RequiredAttributeDescriptor.NameComparisonMode)nameComparison; builder.Value = value; builder.ValueComparisonMode = (RequiredAttributeDescriptor.ValueComparisonMode)valueComparison; foreach (var diagnostic in diagnostics) { var diagnosticReader = diagnostic.CreateReader(); var diagnosticObject = serializer.Deserialize <RazorDiagnostic>(diagnosticReader); builder.Diagnostics.Add(diagnosticObject); } var metadataReader = metadata.CreateReader(); var metadataValue = serializer.Deserialize <Dictionary <string, string> >(metadataReader); foreach (var item in metadataValue) { builder.Metadata[item.Key] = item.Value; } }
private void ParsePlainSelector(RequiredAttributeDescriptorBuilder attributeBuilder) { var nameEndIndex = _requiredAttributes.IndexOfAny(InvalidPlainAttributeNameCharacters, _index); string attributeName; var nameComparison = RequiredAttributeDescriptor.NameComparisonMode.FullMatch; if (nameEndIndex == -1) { attributeName = _requiredAttributes.Substring(_index); _index = _requiredAttributes.Length; } else { attributeName = _requiredAttributes.Substring(_index, nameEndIndex - _index); _index = nameEndIndex; if (_requiredAttributes[nameEndIndex] == RequiredAttributeWildcardSuffix) { nameComparison = RequiredAttributeDescriptor.NameComparisonMode.PrefixMatch; // Move past wild card _index++; } } attributeBuilder.Name = attributeName; attributeBuilder.NameComparisonMode = nameComparison; }
private static void ReadRequiredAttribute(RequiredAttributeDescriptorBuilder builder, JObject attribute, JsonSerializer serializer) { string name = attribute["Name"].Value <string>(); int nameComparisonMode = attribute["NameComparison"].Value <int>(); string value = attribute["Value"].Value <string>(); int valueComparisonMode = attribute["ValueComparison"].Value <int>(); JArray jArray = attribute["Diagnostics"].Value <JArray>(); JObject jObject = attribute["Metadata"].Value <JObject>(); builder.Name = name; builder.NameComparisonMode = (RequiredAttributeDescriptor.NameComparisonMode)nameComparisonMode; builder.Value = value; builder.ValueComparisonMode = (RequiredAttributeDescriptor.ValueComparisonMode)valueComparisonMode; foreach (JToken item2 in jArray) { JsonReader reader = item2.CreateReader(); RazorDiagnostic item = serializer.Deserialize <RazorDiagnostic>(reader); builder.Diagnostics.Add(item); } JsonReader reader2 = jObject.CreateReader(); foreach (KeyValuePair <string, string> item3 in serializer.Deserialize <Dictionary <string, string> >(reader2)) { builder.Metadata[item3.Key] = item3.Value; } }
private bool TryParseCssValueComparison(RequiredAttributeDescriptorBuilder builder, out RequiredAttributeDescriptor.ValueComparisonMode valueComparison) { Debug.Assert(!AtEnd); if (CssValueComparisons.TryGetValue(Current, out valueComparison)) { var op = Current; _index++; if (op != '=' && At('=')) { // Two length operator (ex: ^=). Move past the second piece _index++; } else if (op != '=') // We're at an incomplete operator (ex: [foo^] { //var diagnostic = RazorDiagnosticFactory.CreateTagHelper_PartialRequiredAttributeOperator(op, _requiredAttributes); //builder.Diagnostics.Add(diagnostic); return(false); } } else if (!At(']')) { //var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidRequiredAttributeOperator(Current, _requiredAttributes); //builder.Diagnostics.Add(diagnostic); return(false); } builder.ValueComparisonMode = valueComparison; return(true); }
private bool TryParseCssSelector(RequiredAttributeDescriptorBuilder attributeBuilder) { Debug.Assert(At('[')); // Move past '['. _index++; PassOptionalWhitespace(); ParseCssAttributeName(attributeBuilder); PassOptionalWhitespace(); if (!EnsureNotAtEnd(attributeBuilder)) { return(false); } if (!TryParseCssValueComparison(attributeBuilder, out RequiredAttributeDescriptor.ValueComparisonMode valueComparison)) { return(false); } PassOptionalWhitespace(); if (!EnsureNotAtEnd(attributeBuilder)) { return(false); } if (valueComparison != RequiredAttributeDescriptor.ValueComparisonMode.None && !TryParseCssValue(attributeBuilder)) { return(false); } PassOptionalWhitespace(); if (At(']')) { // Move past the ending bracket. _index++; return(true); } else if (AtEnd) { //var diagnostic = RazorDiagnosticFactory.CreateTagHelper_CouldNotFindMatchingEndBrace(_requiredAttributes); //attributeBuilder.Diagnostics.Add(diagnostic); } else { //var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidRequiredAttributeCharacter(Current, _requiredAttributes); //attributeBuilder.Diagnostics.Add(diagnostic); } return(false); }
public static RequiredAttributeDescriptorBuilder Name(this RequiredAttributeDescriptorBuilder builder, string name) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } builder.Name = name; return(builder); }
internal static bool IsDirectiveAttribute(this RequiredAttributeDescriptorBuilder builder) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } return (builder.Metadata.TryGetValue(ComponentMetadata.Common.DirectiveAttribute, out var value) && string.Equals(bool.TrueString, value)); }
private bool EnsureNotAtEnd(RequiredAttributeDescriptorBuilder builder) { if (AtEnd) { //var diagnostic = RazorDiagnosticFactory.CreateTagHelper_CouldNotFindMatchingEndBrace(_requiredAttributes); //builder.Diagnostics.Add(diagnostic); return(false); } return(true); }
private void ParseCssAttributeName(RequiredAttributeDescriptorBuilder builder) { var nameStartIndex = _index; var nameEndIndex = _requiredAttributes.IndexOfAny(InvalidCssAttributeNameCharacters, _index); nameEndIndex = nameEndIndex == -1 ? _requiredAttributes.Length : nameEndIndex; _index = nameEndIndex; var attributeName = _requiredAttributes.Substring(nameStartIndex, nameEndIndex - nameStartIndex); builder.Name = attributeName; }
public static RequiredAttributeDescriptorBuilder ValueComparisonMode( this RequiredAttributeDescriptorBuilder builder, RequiredAttributeDescriptor.ValueComparisonMode valueComparison) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } builder.ValueComparisonMode = valueComparison; return(builder); }
private void ReadRequiredAttribute(RequiredAttributeDescriptorBuilder builder, JObject attribute, JsonSerializer serializer) { var name = attribute[nameof(RequiredAttributeDescriptor.Name)].Value <string>(); var nameComparison = attribute[nameof(RequiredAttributeDescriptor.NameComparison)].Value <int>(); var value = attribute[nameof(RequiredAttributeDescriptor.Value)].Value <string>(); var valueComparison = attribute[nameof(RequiredAttributeDescriptor.ValueComparison)].Value <int>(); var diagnostics = attribute[nameof(RequiredAttributeDescriptor.Diagnostics)].Value <JArray>(); builder.Name = name; builder.NameComparisonMode = (RequiredAttributeDescriptor.NameComparisonMode)nameComparison; builder.Value = value; builder.ValueComparisonMode = (RequiredAttributeDescriptor.ValueComparisonMode)valueComparison; foreach (var diagnostic in diagnostics) { var diagnosticReader = diagnostic.CreateReader(); var diagnosticObject = serializer.Deserialize <RazorDiagnostic>(diagnosticReader); builder.Diagnostics.Add(diagnosticObject); } }
private bool TryParseCssValue(RequiredAttributeDescriptorBuilder builder) { int valueStart; int valueEnd; if (At('\'') || At('"')) { var quote = Current; // Move past the quote _index++; valueStart = _index; valueEnd = _requiredAttributes.IndexOf(quote, _index); if (valueEnd == -1) { //var diagnostic = RazorDiagnosticFactory.CreateTagHelper_InvalidRequiredAttributeMismatchedQuotes(quote, _requiredAttributes); //builder.Diagnostics.Add(diagnostic); return(false); } _index = valueEnd + 1; } else { valueStart = _index; var valueEndIndex = _requiredAttributes.IndexOfAny(InvalidCssQuotelessValueCharacters, _index); valueEnd = valueEndIndex == -1 ? _requiredAttributes.Length : valueEndIndex; _index = valueEnd; } var value = _requiredAttributes.Substring(valueStart, valueEnd - valueStart); builder.Value = value; return(true); }
public static RequiredAttributeDescriptorBuilder AddDiagnostic(this RequiredAttributeDescriptorBuilder builder, RazorDiagnostic diagnostic) { builder.Diagnostics.Add(diagnostic); return(builder); }