私はこの問題についてインターネット上で何も見つけられていないことを驚いていますが、おそらく間違った言葉を探しています。ここで私は何をする必要があります。
Suppose I have a generic type: List
works for the
sake of simplicity. How do I get the parameter type (in this case
typeof(string)
)?
Keep in mind that I need to do this from outside the generic
class (not inside a class method, which is what I’ve seen in other
SO questions). The bottom line is that I have an instance of a
generic type, I need to know both its type AND its parameter type
(in the example above, I would like to get both
typeof(List)
AND typeof(string)
, not
anything like typeof(List)
). Of course, this must be
done at runtime.
返信するすべての人に感謝します。
ベストアンサー
あなたが探しているものは、 タイプです。 GetGenericArguments()
問題のインスタンスの Type
で呼び出すことになります。 Type
(をEric
Lippertの不気味さに合わせて)。