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 3458886
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:02:22+00:00 2026-05-18T10:02:22+00:00

How do I get using reflection the most generic type from a shared constructor

  • 0

How do I get using reflection the most generic type from a shared constructor in the base class :

Public Class Foo()
   Shared Sub New()
       'Here we have code to get the type!
        MethodBase.GetCurrentMethod().DeclaringType
   End
End Class

Public Class Bar()
  Inherits Foo

End Class

I expect the result to be Bar type and not the Foo. Is it possible?

  • 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-18T10:02:22+00:00Added an answer on May 18, 2026 at 10:02 am

    First, it seems you want to find the most derived type (or the most specific type), not the most generic type — which would mean rather the opposite (either, that generics are involved, or that the most general type is being sought).

    While it may be possible to do this using reflection, your need for it might indicate that you have your class design wrong, or less than optimal.

    First, constructors aren’t virtual methods, so inside a constructor (IIRC), the Me object reference is of the type that contains this constructor.

    What you could do is reflect over all of an assembly’s types and find all those that are derived from Foo. You would then have to build a inheritance graph of these types and assign a number to each saying how far it is derived from Foo (number of inheritance levels). You could then check the Me object reference against all of the types you’ve identified (see if Me can be cast to each of them), and from that subset, choose the one type with the largest number of inheritance levels.

    I hope that from this, you’ll see that it’s probably not worth the effort. It would be more interesting, and probably more helpful, to re-think why you need to do this, and if possible, find a way to avoid it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I get all the public methods of class using reflection when class
Using reflection you can get pretty much everything relating to a class. You can
Possible Duplicate: To get parent class using Reflection on C# I am trying to
Using reflection, how can I get all types that implement an interface with C#
Is there a straightforward way using reflection to get at the parameter list for
How do I get a method using reflection based on a parameter value when
How do I get the actual type of T in a generic List at
Using GWT I have a Java class: public class Pojo { private String name;
I'm using reflection to iterate over all the members of a given type. This
I want to get a notification when object attribute is changed by using reflection.

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.