I have a collection of Types and I want to filter out every Type that is not concrete.
I can see that I can check isAbstract and isInterface to catch most non-concretes, but is this going to miss anything?
Is there an "isConcrete" property?
I guess that if you give a IsClass && !IsAbstract
a try this could work?
if isConcreteType(myType) { DoSomething(); }
bool isConcreteType(Type type) {
return type.IsClass && !type.IsAbstract && !type.IsInterface;
}
As per comment by KC-NH:
Structs are value types and so IsClass will be false. Do you want structs to be considered concrete classes? If so, remove the IsClass condition
So if you want to consider a struct a concrete type, you have to wave away the IsClass
constraint.
bool isConcreteType(Type type) { return !type.IsAbstract && !type.IsInterfaces; }
The opposite of IsAbstract is "is concrete", so you're good with those checks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With