/// <summary> /// Provides the implementation for operations that invoke a member. Classes /// derived from the System.Dynamic.DynamicObject class can override this method /// to specify dynamic behavior for operations such as calling a method. /// </summary> /// <param name="binder"> /// Provides information about the dynamic operation. The binder.Name property /// provides the name of the member on which the dynamic operation is performed. /// For example, for the statement sampleObject.SampleMethod(100), where sampleObject /// is an instance of the class derived from the System.Dynamic.DynamicObject /// class, binder.Name returns "SampleMethod". The binder.IgnoreCase property /// specifies whether the member name is case-sensitive. /// </param> /// <param name="args">The arguments that are passed to the object member during the invoke operation.</param> /// <param name="result">The result of the member invocation.</param> /// <returns>true if the operation is successful; otherwise, false. </returns> public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { var methodName = binder.Name.ToLower(); // Checking to see if an overload of write is called that is not supported. // all supported overloads should be explicitly implemented in this type. if (methodName == "Write") { result = null; return false; } // All string.Concat does is to do a null check on the arg. var attributes = binder.CallInfo.ArgumentNames .Select((it, i) => new HtmlAttribute(RewriteAttributeName(it), string.Concat(args[i]))).ToArray(); if (Array.IndexOf(SelfClosingTags, methodName) == -1) { result = new HtmlTag(this.writer, methodName, attributes); } else { result = null; this.writer.RenderSelfClosingTag(methodName, attributes); } return true; }
/// <summary> /// Creates an HTML tag and adds any provided attributes to the tag. /// </summary> /// <param name="writer"> /// The HTMLTextWriter. /// </param> /// <param name="tag"> /// The type of HTML tag. /// </param> /// <param name="tagStyle"> /// The tag Style. /// </param> /// <param name="attributes"> /// HTML attributes. /// </param> /// <returns> /// HTML tag with attributes. /// </returns> public static HtmlTag RenderTag(this HtmlTextWriter writer, HtmlTextWriterTag tag, HtmlTag.TagStyle tagStyle, params HtmlAttribute[] attributes) { return new HtmlTag(writer, tag, tagStyle, attributes); }
public static HtmlTag RenderTag(this HtmlTextWriter writer, HtmlTextWriterTag tag, HtmlTag.TagStyle tagStyle, string id = null, string cssClass = null) { return RenderTag(writer, tag, tagStyle, ToAttributes(id, cssClass)); }