Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Func delegate with params type

How, in C#, do I have a Func parameter representing a method with this signature?

XmlNode createSection(XmlDocument doc, params XmlNode[] childNodes)

I tried having a parameter of type Func<XmlDocument, params XmlNode[], XmlNode> but, ooh, ReSharper/Visual Studio 2008 go crazy highlighting that in red.

Update: okay, Googling for 'c# params func' produced no results, but 'c# params delegate' led me to this question. Following Jon Skeet's answer there, it looks like maybe I could create a delegate, say Foo, and then instead of having a parameter to my method of type Func<XmlDocument, params XmlNode[], XmlNode>, I take a parameter of type Foo.

like image 352
Sarah Vessels Avatar asked Jun 08 '10 13:06

Sarah Vessels


1 Answers

Jon Skeet's answer to this other question led me to try the following, which works:

protected delegate XmlNode CreateSection(XmlDocument doc,
    params XmlNode[] childNodes);

protected static void createOrUpdateSettingTree(XmlNode rootNode,
    XmlDocument doc, CreateSection createSection) { ... }
like image 77
Sarah Vessels Avatar answered Oct 27 '22 07:10

Sarah Vessels