Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7059355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:13:20+00:00 2026-05-28T04:13:20+00:00

I got a generic Interface like this : public interface IResourceDataType<T> { void SetResourceValue(T

  • 0

I got a generic Interface like this :

public interface IResourceDataType<T>
{
    void SetResourceValue(T resValue);
}

Then I got this class that implements my Interface :

public class MyFont : IResourceDataType<System.Drawing.Font>
{
    //Ctor + SetResourceValue + ...
}

And finally I got a :

var MyType = typeof(MyFont);

I, now, want to get the System.Drawing.Font Type from MyType !
At the moment, I got this code :

if (typeof(IResourceDataType).IsAssignableFrom(MyType))
{
    //If test is OK
}

But I don’t manage to “extract” my Type here…
I tried a couple of things with GetGenericArguments() and other things but they either don’t compile or return a null value/List…
What do I have to do ?

EDIT :
Here is the solution that fit my code for those who will get the same problem :

if (typeof(IResourceDataType).IsAssignableFrom(MyType))
{
    foreach (Type type in MyType.GetInterfaces())
    {
        if (type.IsGenericType)
            Type genericType = type.GetGenericArguments()[0];
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:13:21+00:00Added an answer on May 28, 2026 at 4:13 am

    Since your MyFont class only implements one interface, you can write:

    Type myType = typeof(MyFont).GetInterfaces()[0].GetGenericArguments()[0];
    

    If your class implements several interfaces, you can call the GetInterface() method with the mangled name of the interface you’re looking for:

    Type myType = typeof(MyFont).GetInterface("IResourceDataType`1")
                                .GetGenericArguments()[0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got some generic class for my JPA model POJO that goes like this:
I got an interface like this public interface IWriter { ... } and a
I've got a generic dictionary Dictionary<string, T> that I would like to essentially make
I've got a generic class: public class BaseFieldValue<T> { public BaseFieldValue() { //... }
I've got the following Generic usercontrol declared: public partial class MessageBase<T> : UserControl {
I've got a interface that's implemented as an abstract base class with a number
Say I've got this interface: public interface IFoo { string Text {get;} } And
In my code I've got a generic, getProperty like so: public T getProperty<T>(int GUID,
I've got a generic<> function that takes a linq query ('items') and enumerates through
Hey! I've got a generic package that requires a config file and multiple packages

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.