Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Class inference

Class inference

Scheduled Pinned Locked Moved C#
question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DwR
    wrote on last edited by
    #1

    Hi, I need to determine the parent class from which a particular subclass is derived. Could someone kindly explain to me how I can access that information please? Regards, Dave

    Regards, Dave

    C W C 3 Replies Last reply
    0
    • D DwR

      Hi, I need to determine the parent class from which a particular subclass is derived. Could someone kindly explain to me how I can access that information please? Regards, Dave

      Regards, Dave

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Well this is something you should know at design time, not in code. Why would you need to check in code when a class in C# can only have one parent class ? Can you better explain what you're trying to do ? The is and as keywords let you do stuff like if ( x is mybase) which returns true if the object x is a mybase, either directly or as a parent.

      Christian Graus Driven to the arms of OSX by Vista.

      1 Reply Last reply
      0
      • D DwR

        Hi, I need to determine the parent class from which a particular subclass is derived. Could someone kindly explain to me how I can access that information please? Regards, Dave

        Regards, Dave

        W Offline
        W Offline
        Wendelius
        wrote on last edited by
        #3

        One way to do it is to examine the BaseType. For example: myObject.GetType().BaseType...

        The need to optimize rises from a bad design.My articles[^]

        1 Reply Last reply
        0
        • D DwR

          Hi, I need to determine the parent class from which a particular subclass is derived. Could someone kindly explain to me how I can access that information please? Regards, Dave

          Regards, Dave

          C Offline
          C Offline
          Chamadness
          wrote on last edited by
          #4

          if you have an instance of that class:

          object unknown = ?;
          Type unknownType = unknown.GetType();
          Type toFind = unknownType.BaseType;

          The variable Type will hold the type your class directly inherits from. I hope this answers your question.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups