This project has moved. For the latest updates, please go here.

How to determine if a Type derives from a generic class

Apr 1, 2012 at 4:31 PM
Edited Apr 1, 2012 at 4:33 PM

Using fasterflect is there a way to determine if a System.Type implements or derives from a generic class without specifying the generic type parameter?

Using the Type.Implements extension method, I can tell whether a type derives from SomeGenericClass<string>, but not from SomeGenericClass<>.

Apr 1, 2012 at 4:52 PM

Here's some code that does what I'm looking for: http://stackoverflow.com/a/457708/64334

I was just wondering if Fasterflect supported this.

Coordinator
Apr 3, 2012 at 9:46 PM

It didn't, but now it does ;-)

I've fixed the Implements method so that it also supports open generic interfaces, and added Inherits extensions for classes. There are now also InheritsOrImplements extensions as a convenience for combining the two methods.

I've added a bunch of test cases which I think should cover the spectrum, but if you find a bug or quirk please let me know.

Grab the latest source to enjoy these bits.

Apr 3, 2012 at 10:55 PM
Great! Will this also be available in the NuGet package?

Thanks for Fasterflect. Any time I need to do any reflection I automatically install it.

On Tue, Apr 3, 2012 at 4:46 PM, mertner <notifications@codeplex.com> wrote:

From: mertner

It didn't, but now it does ;-)

I've fixed the Implements method so that it also supports open generic interfaces, and added Inherits extensions for classes. There are now also InheritsOrImplements extensions as a convenience for combining the two methods.

I've added a bunch of test cases which I think should cover the spectrum, but if you find a bug or quirk please let me know.

Grab the latest source to enjoy these bits.

Read the full discussion online.

To add a post to this discussion, reply to this email (fasterflect@discussions.codeplex.com)

To start a new discussion for this project, email fasterflect@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Coordinator
Apr 3, 2012 at 11:01 PM

I don't see why it wouldn't, although I'm not the one doing the NuGet packages (or at least haven't been). I've asked Buu to push out a fresh package, but if nothing materializes I'll probably look into creating one.

To use the code immediately you'll need to get the source and build it locally.

Coordinator
Apr 9, 2012 at 8:03 PM

All, latest release is already on Nuget.