-
When defining a record using a primary constructor:
This results in the following class (shortened): public class Person
{
public Person(string Forename) => this.Forename = Forename;
public Forename { get; init; }
} Great. But it feels strange that we now have a PascalCased constructor parameter. (Forename) Question: Did the team consider automatically camelCasing constructor parameters when using primary constructors? Ex.:
would result in: public class Person
{
public Person(string forename) => Forename = forename;
public Forename { get; init; }
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
I'd imagine that it's because changing case is not a trivial issue (it's not too bad if you assume English). E.g. in English |
Beta Was this translation helpful? Give feedback.
-
You could achieve this using source generators. You write: partial record A(int myInt, string myString) And the source generator generates: partial record A(int myInt, string myString){
private int myInt { get; init; } = myInt;
private string myString { get; init; } = myString;
public int MyInt { get => myInt; init => myInt = value; }
public string MyString { get => myString; init => myString = value; }
} This works correctly for withers, equality, and printing prints |
Beta Was this translation helpful? Give feedback.
-
We discussed this at length in the ldm. Final conclusion was that it was entirely it if scope of the language to drive any casing policy or system here. |
Beta Was this translation helpful? Give feedback.
I'd imagine that it's because changing case is not a trivial issue (it's not too bad if you assume English).
E.g. in English
big
andBIG
are equal when you ignore case, but in Turkish they're not. Since unicode identifiers are allowed it's almost impossible to automatically change case on behalf of the programmer.