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. Replacing method/logic in class and runtime.

Replacing method/logic in class and runtime.

Scheduled Pinned Locked Moved C#
testingquestion
5 Posts 3 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.
  • U Offline
    U Offline
    User 2322509
    wrote on last edited by
    #1

    Is there a way to replace a method in the class at runtime? Basically i want a method in a class to use new logic at runtime. I am trying to write a unit test and want to compare results between old and new logic. therefore, planning to replace a method/logic, or somehow make runtime to redirect calls to my new logic. Thanks.

    A G 2 Replies Last reply
    0
    • U User 2322509

      Is there a way to replace a method in the class at runtime? Basically i want a method in a class to use new logic at runtime. I am trying to write a unit test and want to compare results between old and new logic. therefore, planning to replace a method/logic, or somehow make runtime to redirect calls to my new logic. Thanks.

      A Offline
      A Offline
      Anthony Mushrow
      wrote on last edited by
      #2

      Err, if statement?

      bool cheeseIsGood = true;
      ...
      if(cheeseIsGood)
      {
      MethodOne();
      }
      else
      {
      MethodTwo();
      }

      Or something similar. Just change the bool to false when you want to check the other code, using a button or any other means.

      My current favourite word is: Delicious!

      -SK Genius

      Game Programming articles start -here[^]-

      U 1 Reply Last reply
      0
      • U User 2322509

        Is there a way to replace a method in the class at runtime? Basically i want a method in a class to use new logic at runtime. I am trying to write a unit test and want to compare results between old and new logic. therefore, planning to replace a method/logic, or somehow make runtime to redirect calls to my new logic. Thanks.

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        Have a look at PostSharp[^]

        Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

        1 Reply Last reply
        0
        • A Anthony Mushrow

          Err, if statement?

          bool cheeseIsGood = true;
          ...
          if(cheeseIsGood)
          {
          MethodOne();
          }
          else
          {
          MethodTwo();
          }

          Or something similar. Just change the bool to false when you want to check the other code, using a button or any other means.

          My current favourite word is: Delicious!

          -SK Genius

          Game Programming articles start -here[^]-

          U Offline
          U Offline
          User 2322509
          wrote on last edited by
          #4

          It seems i didn't explain my problem properly. Eg. Assembly a.dll has private method1() I am using a.dll in my unit test. Instead of executing logic of a.dll method1(), i want somehow redirect call to my method1(), which i created in unit test project. thanks.

          A 1 Reply Last reply
          0
          • U User 2322509

            It seems i didn't explain my problem properly. Eg. Assembly a.dll has private method1() I am using a.dll in my unit test. Instead of executing logic of a.dll method1(), i want somehow redirect call to my method1(), which i created in unit test project. thanks.

            A Offline
            A Offline
            Anthony Mushrow
            wrote on last edited by
            #5

            So you have a dll with a private method, and this method is called from within the dll? But you want to redirect all calls to the method to one you created outside of the dll? Meaning that all calls made from with the dll to the usual function would actually be calling a new method that is outside of the dll. Or are you just calling the method inside the dll from outside of it?

            My current favourite word is: Delicious!

            -SK Genius

            Game Programming articles start -here[^]-

            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