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 and overriding

Reflection and overriding

Scheduled Pinned Locked Moved C#
help
4 Posts 2 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.
  • A Offline
    A Offline
    ACorbs
    wrote on last edited by
    #1

    Here is the problem, I have an abstract class that has a public property (type = bool). When setting the Property = true, I need to make sure two virtual functions, in the class, were overridden. I don’t want to make them abstract because they don’t usually need to be overridden. So, I looked for some way to use reflection to do this, but I haven’t made much headway. Any help is greatly appreciated.

    L 1 Reply Last reply
    0
    • A ACorbs

      Here is the problem, I have an abstract class that has a public property (type = bool). When setting the Property = true, I need to make sure two virtual functions, in the class, were overridden. I don’t want to make them abstract because they don’t usually need to be overridden. So, I looked for some way to use reflection to do this, but I haven’t made much headway. Any help is greatly appreciated.

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      ACorbs wrote: I need to make sure two virtual functions, in the class, were overridden. 2 ways I can think of: - use BindingFlags.DeclaredOnly when enquiring the Type for the method(s), if none returned, no override. This is limited to the class your in, might not be what you are looking for. - get the method(s) via reflection, and check for the absence of the NewSlot MethodAttributte flag. This means it the method is overriden in the inheritance chain. xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

      A 1 Reply Last reply
      0
      • L leppie

        ACorbs wrote: I need to make sure two virtual functions, in the class, were overridden. 2 ways I can think of: - use BindingFlags.DeclaredOnly when enquiring the Type for the method(s), if none returned, no override. This is limited to the class your in, might not be what you are looking for. - get the method(s) via reflection, and check for the absence of the NewSlot MethodAttributte flag. This means it the method is overriden in the inheritance chain. xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

        A Offline
        A Offline
        ACorbs
        wrote on last edited by
        #3

        Thanks, I'll give it a shot. You wouldn't happen to know the proc cost of these?

        L 1 Reply Last reply
        0
        • A ACorbs

          Thanks, I'll give it a shot. You wouldn't happen to know the proc cost of these?

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          ACorbs wrote: You wouldn't happen to know the proc cost of these? You just need to check once for each type, after that you can just lookup whether the class is overriden or not eg via a static Hashtable in the base class. xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots

          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