[英]Comparing the run-time type of a generic type
我想獲取所有以“ Foo”開頭的ObjectSet。 我已經在下面編寫了代碼,但是它沒有進入if構造。
foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(context))
{
if (prop.PropertyType == typeof(ObjectSet<>))
{
// It doesn't step here even though
// prop.PropertyType is an ObjectSet`1...
請幫忙。
我懷疑prop.PropertyType
實際上是某些X
ObjectSet<X>
。 您可能想要類似的東西:
if (prop.PropertyType.IsGenericType &&
prop.PropertyType.GetGenericTypeDefinition() == typeof(ObjectSet<>))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.