-1

We can execute a method using .NET reflector. But is there any way to skip a specific step based on some condition while executing a method? For Example :

public fn1()
{
  int a=1,b=2,c=3;
  //Step1
  a=b;
  //Ste2
  b=c;
  //Step3
  c+=1;
}

These Steps will be in a Excel with an additional column "Status"[Active/Inactive]

Now, Using reflection , is there any way to skip the Step that is marked as Inactive?

SabarishV
  • 13
  • 3

1 Answers1

1

I think there might be some misunderstandings about reflection. Reflection is nothing but a way to get access to your classes and members when you don't have their names at compile time.

So, no, when you call fn1 you can't magically skip a step. Neither when calling explicitly nor when doing so using reflection.

However, you can design your code such as to allow the caller to skip the step (even without reflection):

public fn1(bool executeStep2 = true)
{
    int a=1,b=2,c=3;
    //Step1
    a=b;
    //Step2
    if (executeStep2) b=c;
    //Step3
    c+=1;
}

By calling fn1(executeStep2: false) you will skip step 2.

chiccodoro
  • 14,407
  • 19
  • 87
  • 130
  • Thanks chiccodoro. Since the Biz Rule is not to do any change in the method , I searched the alternative. Thanks a lot. – SabarishV Jul 03 '14 at 06:28
  • @SabarishV - I am puzzled that a business rule could mandate how the code implementing the rule must look like. If you need more help with this it is best if you extend your question and explain what exactly your issue is and why you are trying to solve it this way. – chiccodoro Jul 03 '14 at 10:27