0

我创建了一个名为“tag”的方法,它返回一个 HtmlTag 对象并获取“HtmlTag”类型的参数(见下文)。

我试图在没有内联数组的情况下传递参数,但出现错误:“命名参数规范必须在指定所有固定参数后出现”。

该错误仅通过将参数插入内联数组(我真的不想这样做)来解决。

我不能在没有数组的情况下传递参数吗?

protected HtmlTag tag(string tagName, string id = null, string classes = null, 
     Dictionary<string, object> attributes = null, Dictionary<string, object> data = null, 
     string text = null, params HtmlTag[] content)
{yada yada...}

请参阅下面我如何从上面调用该方法:

tag("form", "", attributes: ObjList("...."), content: 
                    tag("input", "token", attributes: ObjList("..." + token + "...")),
                    tag("label", "...", attributes: ObjList("..."), text: "..."),
                    tag("...", "...", attributes: ObjList("...")));

当我在 HtmlTag 的内联数组中插入“内容”参数值时,我没有错误(见下文):

tag("form", "", attributes: ObjList("...."), content: new HtmlTag[] {
                    tag("input", "token", attributes: ObjList("..." + token + "...")),
                    tag("label", "...", attributes: ObjList("..."), text: "..."),
                    tag("...", "...", attributes: ObjList("..."))});
4

1 回答 1

0

感谢 Nyerguds 和 Jcl,我使用重载方法作为答案。似乎这是唯一的方法(内联数组除外)

于 2016-03-25T09:16:12.333 回答