bump langversion to 7.3 #21

Merged
BorderOfExtacy merged 1 commit from tidgp/BOEPassion:csharp7 into mergehell_2 2026-09-27 02:00:49 +00:00
Collaborator

currently LangVersion, which controls what c# language features the compiler will recognize, is set to 2. this is pretty restrictive for no real advantage. for a project targetting net20 like this, the default is all the way up at the maximum of 7.3; this pr sets that explicitly for clarity.

afaik this isn't unusual in ts3 modding; e.g. the modthesims.info guide leaves langversion up at the default 7.3.

this would bring in the ability to use most of 12 years worth of nice improvements to c# without any breaking changes.
a big w is interpolated strings replacing String.Format.
also nice are pattern matching, null-conditional, local functions, expression-body.
of course, some features that would be nice to have like Enum.TryParse just aren't in the DLLs or otherwise depend on runtime support. but a surprising amount are syntactic sugar and disappear after compile-time, so they don't care how old the runtime is.

for the sake of not making the code more schizo i intend to only use the new features in new code in new or rewritten files

some more c# 7.3 showcase
// C# 2.0
string s = o as string;
int n;
if (s != null && int.TryParse(s, out n))
    Console.WriteLine(String.Format("{0}: {1}", s, n));
string t = o == null ? null : o.ToString();

// C# 7.3
if (o is string s && int.TryParse(s, out int n))
    Console.WriteLine($"{s}: {n}");
string t = o?.ToString();
// C# 2.0
int _x = 5;
public int X { get { return _x; } set { _x = value; } }
public string GetName() {
    if (_name == null) throw new ArgumentNullException("_name");
    return _name;
}

// C# 7.3
public int X { get; set; } = 5;
public string GetName() => _name ?? throw new ArgumentNullException(nameof(_name));
currently `LangVersion`, which controls what c# language features the compiler will recognize, is set to 2. this is pretty restrictive for no real advantage. for a project targetting `net20` like this, the default is all the way up at the maximum of 7.3; this pr sets that explicitly for clarity. afaik this isn't unusual in ts3 modding; e.g. the modthesims.info guide leaves langversion up at the default 7.3. this would bring in the ability to use most of 12 years worth of nice improvements to c# without any breaking changes. a big w is interpolated strings replacing String.Format. also nice are pattern matching, null-conditional, local functions, expression-body. of course, some features that would be nice to have like Enum.TryParse just aren't in the DLLs or otherwise depend on runtime support. but a surprising amount are syntactic sugar and disappear after compile-time, so they don't care how old the runtime is. for the sake of not making the code more schizo i intend to only use the new features in new code in new or rewritten files <details> <summary>some more c# 7.3 showcase</summary> ```cs // C# 2.0 string s = o as string; int n; if (s != null && int.TryParse(s, out n)) Console.WriteLine(String.Format("{0}: {1}", s, n)); string t = o == null ? null : o.ToString(); // C# 7.3 if (o is string s && int.TryParse(s, out int n)) Console.WriteLine($"{s}: {n}"); string t = o?.ToString(); ``` ```cs // C# 2.0 int _x = 5; public int X { get { return _x; } set { _x = value; } } public string GetName() { if (_name == null) throw new ArgumentNullException("_name"); return _name; } // C# 7.3 public int X { get; set; } = 5; public string GetName() => _name ?? throw new ArgumentNullException(nameof(_name)); ``` </details>
BorderOfExtacy merged commit 545baaf303 into mergehell_2 2026-09-27 02:00:49 +00:00
Sign in to join this conversation.
No description provided.