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. Reflection help - child classes

Reflection help - child classes

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 1 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
    David Wengier
    wrote on last edited by
    #1

    I have a base class, that defines an Enum. I have one or more sub classes that redefine that Enum (using the new keyword). I am trying to write code in the base class to iterate through the enum, as defined by the subclass that is calling the code. Any ideas how? I'm trying to work my way through Reflection, and I can get all of the properties and methods, but cant get any info about any Enums that might be there. Thanks -- Dave

    D 1 Reply Last reply
    0
    • D David Wengier

      I have a base class, that defines an Enum. I have one or more sub classes that redefine that Enum (using the new keyword). I am trying to write code in the base class to iterate through the enum, as defined by the subclass that is calling the code. Any ideas how? I'm trying to work my way through Reflection, and I can get all of the properties and methods, but cant get any info about any Enums that might be there. Thanks -- Dave

      D Offline
      D Offline
      David Wengier
      wrote on last edited by
      #2

      In case anyone cares:

      		// Create a variable, but from the inherited class, not this base class
      		Type\[\] tNested = this.GetType().GetNestedTypes(System.Reflection.BindingFlags.NonPublic);
      		object rt = null;
      		foreach (Type t in tNested)
      		{
      			rt = Activator.CreateInstance(t);
      			break;
      		}
      

      -- Dave

      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