Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine whether a property is a Generic Type in DNX Core 5.0?

Previously I could use this to get the generic types on a class;

typeof(MyClass).GetTypeInfo().DeclaredProperties.Any(p => p.PropertyType.IsGenericType)

However, in DNX Core 5.0, IsGenericType is not supported. What can I use now?

like image 940
Stafford Williams Avatar asked Feb 10 '23 00:02

Stafford Williams


1 Answers

Just looked through some source here that confirms there is still a IsGenericType property in the framework.

https://github.com/aspnet/Common/blob/dev/src/Microsoft.Framework.ClosedGenericMatcher.Sources/ClosedGenericMatcher.cs#L44

Does the following work?

typeof(MyClass).GetTypeInfo().DeclaredProperties.Any(p => p.PropertyType.GetTypeInfo().IsGenericType)
like image 193
Andreas Avatar answered Feb 11 '23 15:02

Andreas