0

I have created a method called "tag" that returns an HtmlTag object and get params of type "HtmlTag" (See below).

I'm trying to pass the params without an inline array but I get an error: "Named argument specifications must appear after all fixed arguments have been specified".

The error resolved only by inserting the params in an inline array (which I really don't want to).

Can't I pass the params without an array?

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...}

See below how I call the method from above:

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

I have no errors when I insert the "content" params value inside an inline array of HtmlTag (see below):

tag("form", "", attributes: ObjList("...."), content: new HtmlTag[] {
                    tag("input", "token", attributes: ObjList("..." + token + "...")),
                    tag("label", "...", attributes: ObjList("..."), text: "..."),
                    tag("...", "...", attributes: ObjList("..."))});
quadroid
  • 8,444
  • 6
  • 49
  • 82
Loves2Develop
  • 774
  • 1
  • 8
  • 29
  • 3
    If you want to pass the arguments named, I don't think there's a way other than making it an array. Named arguments and `params` don't get along well – Jcl Mar 25 '16 at 08:43
  • Named and optional arguments... ugh. So very VB. Use proper overloads. – Nyerguds Mar 25 '16 at 09:07

1 Answers1

0

Thanks to Nyerguds and Jcl I'm using overloaded method as an answer. Seems like it is the only way to go (other than inline array)

Loves2Develop
  • 774
  • 1
  • 8
  • 29
  • 2
    It's possible that since `params` are _always_ the last arguments, all you needed to do was leave off the `content:` name, though. The system probably would detect that all these `HtmlTag` args were the correct type for the `params` that way. – Nyerguds Mar 25 '16 at 09:20