[Proposal] Allow static keyword before arbitrary expression, defining an anymous static field in the surrounding type #7825
-
This would be a generalization of static lambdas in some sense in that instead of just static anonymous delegate fields you could define static fields of an arbitrary type. Meant for cases where moving out an expression into a static field would help performance but would unnecessarily disconnect the code from its usage context. Maybe there wouldn't be a good name for it except for Bogus example using a parser combinator library such as Sprache using MyParserCombinatorLibrary;
public static class MyParsers
{
public static Parser<int> MyParserWhichCanHaveAGoodName =
from x in static ComplexSubParserExpression(123, 321)
from x in static AnotherSubExpression(123, 321)
select x
;
} Somewhat related is the code fix suggested for CA1861. Using this language feature it could propose something like this instead: // A method argument
string message = string.Join(" ", static ["Hello", "world!"]); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
See: #832 Which suggests both |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
See: #832
Which suggests both
static
locals as well asstatic
expressions.