Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use F#'s Ticked Function name notation for C# Methods?

Tags:

c#

f#

In the F# language it is possible to name functions using ``Ticked function name notation``. It is extremely convenient for unit tests naming.

Is there any possibility to do this in the C# language? We can always use Underscored_method_names or PascalMethodNames, but it isn't as easy to read.

like image 586
Dmitrii Lobanov Avatar asked Mar 19 '14 18:03

Dmitrii Lobanov


2 Answers

No, basically. C# type and member names cannot include whitespace (and cannot start with a number). There is support for disambiguating names from reserved keywords (the @ prefix), but that is about it.

When the long name is for display, often DisplayNameAttribute is useful, i.e.

[DisplayName("My class")]
public class MyClass {
    [DisplayName("Full name")]
    public string FullName {get;set;}
}
  • but this won't help with your unit test desires.
like image 143
Marc Gravell Avatar answered Sep 18 '22 12:09

Marc Gravell


Putting actual spaces (ASCII 32) in identifier names is not possible.

However, see this blog about (ab)using Unicode to insert other code points that look like spaces. The author describes a way to somewhat automate this using hotkeys.

I do not recommend you do this as it will cause serious problems with maintainability and debugging.

like image 27
TypeIA Avatar answered Sep 19 '22 12:09

TypeIA