dotnet / dotnet/csharp-tmLanguage
Add more C# language features and syntax sugar to highlightning
- Dominant language
- TypeScript
- Stars
- 78
- Forks
- 43
- Avg merge
- 34m
- Merged PRs (30d)
- 1
Description
See https://github.com/github/linguist/issues/5838
## Describe the enhancement
Currently not all syntax features of C# are highlighted.
My suggestion includes the following (if you would find something missing, feel free to add):
## Missing features
For the sake of completeness, I have tried to explicitly assign a feature to a language version here. I could not find the associated standard/proposal for each feature but they do exist.
### Standard (Draft v6)
[C# language standard](https://github.com/dotnet/csharpstandard) - [ECMA-TC49-TG2](https://www.ecma-international.org/task-groups/tc49-tg2/)
**Unsafe blocks** ([ECMA Draftv6 22.2](https://github.com/dotnet/csharpstandard/blob/draft-v6/standard/unsafe-code.md#222-unsafe-contexts))
```c#
public void Method() {
unsafe {
// Unsafe operations
}
}
```
**Pointers & pointer fixture** ([ECMA Draftv6 22.7](https://github.com/dotnet/csharpstandard/blob/draft-v6/standard/unsafe-code.md#227-the-fixed-statement))
```c#
public unsafe void Method() {
fixed(int* ptr = &refVar) {
// Some cool pointer operations
}
}
```
### C# 9
**Native Integer Primitives** ([CSharp 9.0 Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-9.0/native-integers.md))
```c#
public void Method() {
nint myNativeInteger = -123;
nuint myNativeUnsignedInteger = 123;
}
public void Method(nint param1, nuint param2) {}
```
**Function pointers** ([CSharp 9.0 Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-9.0/function-pointers.md))
```c#
public void Method() {
delegate* managed;
delegate* unmanaged;
delegate* unmanaged[Cdecl] ;
delegate* unmanaged[Stdcall, SuppressGCTransition] ;
}
```
**Static anonymous functions** ([CSharp 9.0 Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-9.0/static-anonymous-functions.md))
```c#
public void X() {
Y(static (i) => i + 1);
Y(static i => i + 1);
}
public void Y(Func x) {}
```
**With expressions** ([CSharp 9.0 Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-9.0/records.md#with-expression))
```c#
public record MyRecord(string Name);
public MyRecord ModifyName(MyRecord rec) {
return rec with { Name = "My new name" };
}
```
### C# 10
**Global Using Directives** ([CSharp 10.0 Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-10.0/GlobalUsingDirective.md))
```c#
global using System;
global using System.Linq;
global using System.Runtime.CompilerServices;
```
**Records** ([CSharp 10.0 Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-10.0/record-structs.md))
```c#
public partial record struct Record {}
public partial sealed record Record {}
public record struct Record {}
public sealed record Record {}
```
**Enhanced Pattern Matching** ([CSharp 9.0 Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-9.0/patterns3.md) + [CSharp 10.0 Proposal](https://github.com/dotnet/csharplang/blob/main/proposals/csharp-10.0/extended-property-patterns.md))
```c#
void M(object o1, object o2)
{
var t = (o1, o2);
if (t is (int, string)) {}
switch (o1) {
case int: break;
case string: break;
}
}
bool IsLetter(char c) => c is (>= 'a' and <= 'z') or (>= 'A' and <= 'Z');
```
**Null checks**
```c#
public void Method(object? nullable) {
if(nullable is null) {}
if(nullable is not null) {}
}
```
**Defaults**
```c#
public void X() {
int x = default;
}
```
**implicit new**
```c#
public void Method() {
MyKnownType value = new();
}
```
## Wrong implemented features
**Extension method resolving**
```c#
namespace N1
{
public static class D
{
public static void F(this int i) => Console.WriteLine($"D.F({i})");
}
}
namespace N2
{
using N1;
class Test
{
static void Main(string[] args)
{
1.F();
// ^^ Why is this red?
}
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.