0
public class MyClass
{
    private Func<string, string> KeyTransformer;

    public MyClass(Func<string, string> keyTransformer)
    {
        KeyTransformer = keyTransformer;
    }

    public string DoSomething(string input)
    {
        return KeyTransformer(input);
    }
}

Obviously Resharper suggests me to rename the "field" to _keyTransformer.

But it feels wrong to write something like that:

string newKey = _keyTransformer("input");

So question #1 is: Pascal casing or camel casing?

And question #2 is (in case it is pascal): How do I tell Resharper it's okay to have pascal casing for Func?

Carnifex
  • 533
  • 3
  • 10
lapsus
  • 2,915
  • 2
  • 32
  • 61
  • Any particular reason you've got a field rather than an autoproperty? – AakashM Nov 19 '13 at 13:54
  • If he don't want to expose "KeyTransformer" outside of MyClass why he should use autoproperty? Just don't say "private property" :P – Carnifex Dec 07 '13 at 10:49

2 Answers2

0

Which style is going to be clearer to the next person to read the code?

In this case you're doing something a little unusual (calling a method stored in a field) so the fact the syntax makes it stand out is no bad thing.

Matthew Strawbridge
  • 19,940
  • 10
  • 72
  • 93
0

It's private field so camel case.

Rule SA1306 : Variable names and private field names must start with a lower-case letter: {0}.

It's not obvious to (in case of R#) suggest underline.

Rule SA1309 : Field names must not start with an underscore.

So you have to change behavior of your R# :) In my case after installing StyleCop (4.7.47) and open project in VS, R# notify my that some rules are not consistent with StyleCop and asked my if I want to change it. So I have the same rules in R# and StyleCop (eg. naming convention for private fields)

public class MyClass
{
    private Func<string, string> keyTransformer;

    public MyClass(Func<string, string> keyTransformer)
    {
        this.keyTransformer = keyTransformer;
    }

    public string DoSomething(string input)
    {
        return keyTransformer(input);
    }
}
Carnifex
  • 533
  • 3
  • 10