views:

90

answers:

4

Hi All,

I have a constructor signature like this

public NavigationLink(Func<String> getName, 
                      Func<UrlHelper, String> getURL, 
                      Func<bool> isVisible, 
                      IEnumerable<NavigationLink> subItems)

Inside that constructor I am assigning the getName to a property of the containing class

GetName = getName

I have a string extension that does casing on a string call String.CapitalizeWords();

How do I apply that extension to the Func?

Thanks

+4  A: 

You could do

GetName = () => getName().CapitalizeWords();

But why do you need a parameterless function, returning a String instead of the String itself?

Jens
I didn't write this. One of the developers I work with has a thing for all these delegates. I just go /sigh a lot.
Mike
You don’t need the to call the constructor explicitly, i.e. the `new Func<String>` wrapper. Just the lambda is fine.
Konrad Rudolph
I'll edit that in.
Jens
A: 

It will be there for the results of running getName, not on getName itself. GetName is a delegate to a function that will return a string; it is not itself a string. You should be able to do String CapName = GetName().CapitalizeWords().

Patrick Karcher
Ya. I should have specialized however that the property in the class is not of type String but instead of Func<String>. /sigh much?
Mike
ah, gotcha. The other guys saw it that way, so you got a good answer. Wow, that guys does like delegates, doesn't he?
Patrick Karcher
A: 
GetName = () => getName().CapitalizeWords();
Darin Dimitrov
+1  A: 

So is this the signature for the GetName property?

string GetName{get;set;}

If so, I guess all you need to do is

GetName=getName().CapitalizeWords();

Otherwise if the signature is like this:

Func<string> GetName{get;set;}

you'd probably need to do

GetName=getName;
string caps = GetName().CapitalizeWords();

I hope I understood your question :P

bottlenecked