LoginSignup
4
0

More than 3 years have passed since last update.

2020 で一番期待している C# の機能

Posted at

Champion "Allow Generic Attributes" · Issue #124 · dotnet/csharplang

Generic な Attribute が使えるようになる、予定。 Null check parameter も捨てがたかったけど、これでコードを綺麗に出来る部分が増えてきそうで楽しみです。あくまで気がするだけ。それとデザイン決定の会話をあんまり見ていないので、もしかしたら違ったり、実際に使えるようになったらこれは NG みたいなのもあるかもしれません。

どんなコードが書けるか

こういうクラスがあって、

class GenericAttribute<T> : Attribute
{
}

こんな感じで使う。と、思う。

[Generic<string>]
public string MethodA()
{
}

public string MethodB([Generic<int>]int id)
{
}

[Generic<MyClass>]
public MyClass HogeHoge { get; set; }

Note

コンパイラのステータスは roslyn/Language Feature Status.md at master · dotnet/roslyn です。 C# はこっち Language Version Planning だと思います。

現状は C# 9.0 に Generic Attributes は入っていないように見えるので、もしかしたら入るかもしれないし、その次の C# 10.0 かもしれないし、もっと先の C# なのかもしれません。

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0