public static bool IsDefaultKind(this BoundAttributeParameterDescriptor parameter) { if (parameter == null) { throw new ArgumentNullException(nameof(parameter)); } return(string.Equals(parameter.Kind, TagHelperConventions.DefaultKind, StringComparison.Ordinal)); }
public static string GetPropertyName(this BoundAttributeParameterDescriptor parameter) { if (parameter == null) { throw new ArgumentNullException(nameof(parameter)); } parameter.Metadata.TryGetValue(TagHelperMetadata.Common.PropertyName, out var propertyName); return(propertyName); }
public static bool TryGetFirstBoundAttributeMatch( string name, TagHelperDescriptor descriptor, out BoundAttributeDescriptor boundAttribute, out bool indexerMatch, out bool parameterMatch, out BoundAttributeParameterDescriptor boundAttributeParameter) { indexerMatch = false; parameterMatch = false; boundAttribute = null; boundAttributeParameter = null; if (string.IsNullOrEmpty(name) || descriptor == null) { return(false); } // First, check if we have a bound attribute descriptor that matches the parameter if it exists. foreach (var attribute in descriptor.BoundAttributes) { boundAttributeParameter = attribute.BoundAttributeParameters.FirstOrDefault( p => SatisfiesBoundAttributeWithParameter(name, attribute, p)); if (boundAttributeParameter != null) { boundAttribute = attribute; indexerMatch = SatisfiesBoundAttributeIndexer(name, attribute); parameterMatch = true; return(true); } } // If we reach here, either the attribute name doesn't contain a parameter portion or // the specified parameter isn't supported by any of the BoundAttributeDescriptors. foreach (var attribute in descriptor.BoundAttributes) { if (CanSatisfyBoundAttribute(name, attribute)) { boundAttribute = attribute; indexerMatch = SatisfiesBoundAttributeIndexer(name, attribute); return(true); } } // No matches found. return(false); }
public static bool SatisfiesBoundAttributeWithParameter(string name, BoundAttributeDescriptor parent, BoundAttributeParameterDescriptor descriptor) { if (TryGetBoundAttributeParameter(name, out var attributeName, out var parameterName)) { var satisfiesBoundAttributeName = SatisfiesBoundAttributeName(attributeName, parent); var satisfiesBoundAttributeIndexer = SatisfiesBoundAttributeIndexer(attributeName, parent); var matchesParameter = string.Equals(descriptor.Name, parameterName, StringComparison.Ordinal); return((satisfiesBoundAttributeName || satisfiesBoundAttributeIndexer) && matchesParameter); } return(false); }