开发者

How do I apply a String extension to a Func<String>

I have a constructor signature like this

public NavigationLink(Func<String> getName, 
                      Func<UrlHelper, String> getURL, 
               开发者_如何学JAVA       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


You could do

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

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


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


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().


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜