vscode-csharp-snippets
vscode-csharp-snippets copied to clipboard
Added record struct and switch expression snippet, added a placeholder name for records
Record struct snippets
Added snippets:
records - Mutable positional record struct
public record struct MyRecord(string Name);
recordsd - Mutable struct record with deconstructor
public record struct MyRecord
{
public MyRecord(string name, int age) => (Name, Age) = (name, age);
public string Name { get; set; }
public int Age { get; set; }
public void Deconstructor(out string name, out int age) => (name, age) = (Name, Age);
}
recordsr - Immutable positional record struct
public readonly record struct MyRecord(string Name);
Record changes
Changed the default type name for records from Person to a placeholder with the default text MyRecord. This should keep records inline with class and struct snippets. I'm not sure if this would be considered a breaking change as its adding another placeholder and may break muscle memory for users.
Switch expression snippet
Added a snippet for switch expressions from C# 8.0.
switche - Switch expression
value switch
{
value1 => value2,
_ => default,
};
Realigned the deconstructor for recordd and recordsd
From:
...
public int Age { get; set; }
public void Deconstructor(out string name, out int age) => (name, age) = (Name, Age);
}
...
public int Age { get; set; }
public void Deconstructor(out string name, out int age) => (name, age) = (Name, Age);
}