This question is being asked because I have no prior experience with delegate best practices
I have a unordered lists in html, where the structure is the same throughout my site, but the content of the lists may differ.
Examples:
List of object A
<ul>
<li>
<ul>
<li>A.someMember1</li>
<li>A.someMember2</li>
<li>A.someMember3</li>
</ul>
</li>
</ul>
List of object B
<ul>
<li>
<ul>
<li>B.someMember1</li>
<li>B.someMember2</li>
<li>B.someMember3</li>
<li>B.someMember4</li>
</ul>
</li>
</ul>
I created two delegates:
protected delegate void RenderHtmlMethod(HtmlTextWriter writer);
protected delegate void RenderHtmlMethodWithObjects(HtmlTextWriter writer, object obj);
and the following method
private void RenderList(HtmlTextWriter writer, string title, RenderHtmlMethod headingDelegate,
RenderHtmlMethodWithObjects itemsDelegate, object objToRender)
{
writer.RenderBeginTag(HtmlTextWriterTag.Fieldset);
writer.RenderBeginTag(HtmlTextWriterTag.Legend);
writer.HtmlEncode(title);
writer.RenderEndTag();//end Legend
writer.AddAttribute(HtmlTextWriterAttribute.Class, "resultList");
writer.RenderBeginTag(HtmlTextWriterTag.Ul);
{
headingDelegate(writer);
itemsDelegate(writer, objToRender);
}
writer.RenderEndTag();//ul
writer.RenderEndTag(); //fieldset
}
That way, I can make methods that render the heading (just another li with an embedded ul) and then render the necessary list items for each list of object.
I can't redefine my classes to implement any interfaces, although, I could create a wrapper for the classes and implement the render method there. What do you think about this?
Does my structure make sense? Or am I insane?