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

  • SEARCH
  • Home
  • 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 6155661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:28:26+00:00 2026-05-23T20:28:26+00:00

When we have something like this: interface ISomething<U,V> { … } class Something<U,V> :

  • 0

When we have something like this:

interface ISomething<U,V> { ... }
class Something<U,V> : ISomething<U,V> { ... }

typeof(ISomething<,>) and typeof(Something<,>) will result in a “Generic type definition”. But if we get to the interface type as the interface implemented by the class, it will be a constructed type, that none of its type parameters are actually bound:

typeof(Something<,>).GetInterfaces().SingleOrDefault()

MSDN specifically mentions this. What I want, is to construct the same type (constructed type) of ISomething<,> directly (without sub-classing and them looking for the base type), and I could not find any way to do so.

Additional info:

I even tried this:

Type t1 = typeof(ISomething<,>);
Type t2 = t1.MakeGenericType(t1.GetGenericArguments()) // Yields a generic type definition

Type t3 = typeof(Something<,>).GetInterfaces().SingleOrDefault();

In the above code:

t1.Equals(t2) is true, but t1.Equals(t3) is false, obviously because t3 is constructed.

Surprisingly, t1.GetGenericArguments()[0].Equals(t3.GetGenericArguments()[0]) is false, although both are open (IsGenericParameter = true), and I couldn’t find any difference in their properties.

And here’s why I need to do this: I need a canonical form of storing Type objects in a list. The objects sometimes come from base classes / interfaces (such as t3 above) and sometimes directly (such as t1). I will need to be able to compare these to each other. I can’t store the generic type definition (using .GetGenericTypeDefinition()) because sometimes I will have a partially open constructed generic type (like ISomething), and GetGenericTypeDefinition will give me a type without any type arguments specified.

The only way for making the types canonical that I’ve thought might work, is to check if all of the type arguments are unbound, and do a GetGenericTypeDefinition. Otherwise keep the constructed type.

  • 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-23T20:28:26+00:00Added an answer on May 23, 2026 at 8:28 pm

    You are getting yourself all messed up here. Examine the output of this program and make sure that you understand it. Here I’ve alpha-renamed the type parameters so that there is no unclarity due to two things both named U:

    interface I<S, T>
    {
        I<S, T> M();
    }
    
    class C<U, V> : I<U, V>
    {
        public I<U, V> M() {return null;}
        public C<U, V> N() {return null;}
    }
    
    public class MainClass
    {
        public static void Main()
        {
            var i1 = typeof(I<,>);
            var i2 = typeof(I<int, int>);
            var i3 = i2.GetGenericTypeDefinition();
            var i4 = i1.GetMethod("M").ReturnType;
    
            var c1 = typeof(C<,>);
            var c2 = typeof(C<int, int>);
            var c3 = c2.GetGenericTypeDefinition();
            var c4 = c1.GetMethod("N").ReturnType;
    
            var i5 = c1.GetMethod("M").ReturnType;
            var i6 = c1.GetInterfaces()[0];
    
            System.Console.WriteLine(i1 == i2); // false -- I<,> is not I<int, int>
            System.Console.WriteLine(i1 == i3); // true  -- I<int,int>'s decl is I<,>
            System.Console.WriteLine(i1 == i4); // true  -- I<,> is I<S, T>
            System.Console.WriteLine(i1 == i5); // false -- I<S, T> is not I<U, V>
            System.Console.WriteLine(i1 == i6); // false -- I<S, T> is not I<U, V>
    
            System.Console.WriteLine(c1 == c2); // false -- C<,> is not C<int, int>
            System.Console.WriteLine(c1 == c3); // true  -- C<int,int>'s decl is C<,>
            System.Console.WriteLine(c1 == c4); // true  -- C<,> is C<U,V>
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a class that implements the IDisposable interface. Something like this:
I have something like this: public interface IBaseService<TObject> public class BaseService<TObject, TRepository> : IBaseService<TObject>
I have a marker interface something like this: [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)] public class MyAttribute
I basically have something like this: void Foo(Type ty) { var result = serializer.Deserialize<ty>(inputContent);
I have something like this: <div class=content> <a href=#>A</a> </div> <div class=content> <a href=#>B</a>
Sounds like a weird question, but say I have something like this: $.post( /myajax.php,
I have something like this: uses MSXML2_TLB; type TDocumentType = (dtOrder, dtInvoice, dtStatus, dtError);
I have type hierarchy defined like this: interface IMyClass { } interface IBase1<T> {
I have a viewController called HaveScrollController, and this is something like this: @interface HaveScrollController
I have something like this: public class CPerson: INotifyPropertyChanged public class CPeople: SortedSet<CPerson> public

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.