クラス MyGeneric<T> と、型 MyGeneric<string>、MyGeneric<int>、MyGeneric<double> などから作成されたいくつかのキャッシュ データがあります。
どこかで特定のデータをチェックして、それが MyGeneric かどうかを確認する必要があるため、次のようにコーディングします。
if (data is MyGeneric<>) { // can't compile
// ... do something
}
また
if (data.GetType() == typeof(MyGeneric<>)
|| typeof(MyGeneric<>).isAssginableFrom(data.GetType())) {
// no exception but none of these comparison works
}
または、この種の愚かな実装は機能しますが、破棄したいと思います:
if (data.GetType().Name.StartsWith(typeof(MyGeneric<>).Name) { ... }
実際のデータ型とオープン ジェネリック型 (MyGeneric<>) の関係を確認する方法はありますか?