public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var value = reader.ReadAsString(); if (value == null) { ThrowInvalidFormatException(); } var match = Regex.Match(value, @"^([a-zA-Z0-9]+)\[([a-zA-Z0-9]+)\]$"); if (!match.Success) { ThrowInvalidFormatException(); } if (existingValue == null) { existingValue = new HtmlTagAttributePair(); } var pair = (HtmlTagAttributePair)existingValue; pair.TagName = match.Groups[1].Value; pair.AttributeName = match.Groups[2].Value; return(pair); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var value = reader.ReadAsString(); if (value == null) { ThrowInvalidFormatException(); } var match = Regex.Match(value, @"^([a-zA-Z0-9]+)\[([a-zA-Z0-9]+)\]$"); if (!match.Success) { ThrowInvalidFormatException(); } if (existingValue == null) { existingValue = new HtmlTagAttributePair(); } var pair = (HtmlTagAttributePair) existingValue; pair.TagName = match.Groups[1].Value; pair.AttributeName = match.Groups[2].Value; return pair; }
/// <summary> /// Renders the begin tag without end char. /// </summary> private void RenderBeginTagCore(string name) { writer.Write("<"); if (string.IsNullOrWhiteSpace(name)) { throw new InvalidOperationException("HtmlWriter cannot render tag, because tag name is empty."); } writer.Write(name); foreach (DictionaryEntry attr in dataBindAttributes) { AddAttribute("data-bind", attr.Key + ": " + ConvertHtmlAttributeValue(attr.Value), true, ", "); } dataBindAttributes.Clear(); if (attributes.Count > 0) { foreach (DictionaryEntry attr in attributes) { var attributeName = (string)attr.Key; var attributeValue = ConvertHtmlAttributeValue(attr.Value); // allow to use the attribute transformer var pair = new HtmlTagAttributePair() { TagName = name, AttributeName = attributeName }; HtmlAttributeTransformConfiguration transformConfiguration; if (requestContext.Configuration.Markup.HtmlAttributeTransforms.TryGetValue(pair, out transformConfiguration)) { // use the transformer var transformer = transformConfiguration.GetInstance(); transformer.RenderHtmlAttribute(this, requestContext, attributeName, attributeValue); } else { WriteHtmlAttribute(attributeName, attributeValue); } } } attributes.Clear(); }
public bool Equals(HtmlTagAttributePair other) { return(string.Equals(TagName, other.TagName, StringComparison.OrdinalIgnoreCase) && string.Equals(AttributeName, other.AttributeName, StringComparison.OrdinalIgnoreCase)); }
public bool Equals(HtmlTagAttributePair other) { return string.Equals(TagName, other.TagName, StringComparison.OrdinalIgnoreCase) && string.Equals(AttributeName, other.AttributeName, StringComparison.OrdinalIgnoreCase); }
/// <summary> /// Renders the begin tag without end char. /// </summary> private void RenderBeginTagCore(string name) { writer.Write("<"); writer.Write(name); //if(openTags.Peek().AutomaticAttributes != null) //{ // foreach (DictionaryEntry attr in openTags.Peek().AutomaticAttributes) // { // if(attr.Value is IEnumerable) // { // foreach (var val in (IEnumerable)attr.Value) // { // AddAttribute((string)attr.Key, val.ToString(), true); // } // } // else // { // AddAttribute((string)attr.Key, attr.Value.ToString(), true); // } // } //} if (attributes.Count > 0) { foreach (DictionaryEntry attr in attributes) { var attributeName = (string)attr.Key; var attributeValue = (string)attr.Value; // allow to use the attribute transformer var pair = new HtmlTagAttributePair() { TagName = name, AttributeName = attributeName }; HtmlAttributeTransformConfiguration transformConfiguration; if (requestContext.Configuration.Markup.HtmlAttributeTransforms.TryGetValue(pair, out transformConfiguration)) { // use the transformer var transformer = transformConfiguration.GetInstance(); transformer.RenderHtmlAttribute(this, requestContext, attributeName, attributeValue); } else { WriteHtmlAttribute(attributeName, attributeValue); } } } attributes.Clear(); }