/// <summary> /// Write the attribute name to the output stream. /// </summary> /// <remarks> /// Writes the attribute name to the output stream. /// </remarks> /// <param name="id">The attribute identifier.</param> /// <exception cref="System.ArgumentException"> /// <paramref name="id"/> is not a valid HTML attribute identifier. /// </exception> /// <exception cref="System.InvalidOperationException"> /// The <see cref="HtmlWriter"/> is not in a state that allows writing attributes. /// </exception> /// <exception cref="System.ObjectDisposedException"> /// The <see cref="HtmlWriter"/> has been disposed. /// </exception> public void WriteAttributeName(HtmlAttributeId id) { if (id == HtmlAttributeId.Unknown) { throw new ArgumentException("Invalid attribute.", "id"); } if (WriterState == HtmlWriterState.Default) { throw new InvalidOperationException("Cannot write attributes in the Default state."); } CheckDisposed(); EncodeAttributeName(id.ToString()); }
/// <summary> /// Converts the enum value into the equivalent attribute name. /// </summary> /// <remarks> /// Converts the enum value into the equivalent attribute name. /// </remarks> /// <returns>The attribute name.</returns> /// <param name="value">The enum value.</param> public static string ToAttributeName(this HtmlAttributeId value) { var name = value.ToString(); #if NETSTANDARD1_0 || NETSTANDARD1_3 || NETSTANDARD1_6 var field = typeof(HtmlAttributeId).GetTypeInfo().GetDeclaredField(name); var attrs = field.GetCustomAttributes(typeof(HtmlAttributeNameAttribute), false).ToArray(); #else var field = typeof(HtmlAttributeId).GetField(name); var attrs = field.GetCustomAttributes(typeof(HtmlAttributeNameAttribute), false); #endif if (attrs != null && attrs.Length == 1) { return(((HtmlAttributeNameAttribute)attrs[0]).Name); } return(name.ToLowerInvariant()); }
/// <summary> /// Write the attribute name to the output stream. /// </summary> /// <remarks> /// Writes the attribute name to the output stream. /// </remarks> /// <param name="id">The attribute identifier.</param> /// <exception cref="System.ArgumentException"> /// <paramref name="id"/> is not a valid HTML attribute identifier. /// </exception> /// <exception cref="System.InvalidOperationException"> /// The <see cref="HtmlWriter"/> is not in a state that allows writing attributes. /// </exception> /// <exception cref="System.ObjectDisposedException"> /// The <see cref="HtmlWriter"/> has been disposed. /// </exception> public void WriteAttributeName (HtmlAttributeId id) { if (id == HtmlAttributeId.Unknown) throw new ArgumentException ("Invalid attribute.", "id"); if (WriterState == HtmlWriterState.Default) throw new InvalidOperationException ("Cannot write attributes in the Default state."); CheckDisposed (); EncodeAttributeName (id.ToString ()); }