0

I have a library that is shared between an ASP.NET and a Winforms application, and there are 2 function implementations within it (should switch depending on a platform it is currently running on).

Unfortunately I cannot change the winforms app to isolate the logic from UI elements (this is how it's done now), so I need to be able to make a switch within the library code depending on environment.

EDIT: Something like this

if(ASP.NET){
   myFuncSilent();
} else {
   myFuncWithDialogs();   
}

myFuncWithDialogs(){
   System.Windows.Forms.MessageBox.Show('test');
}
myFuncSilent(){
   saveInLog('test');
}
AnKing
  • 1,994
  • 6
  • 31
  • 54
  • 1
    What do you mean by "platform" and "environment"? Operating System, or something else? – Rufus L Dec 06 '18 at 18:07
  • @RufusL ASP.NET or windows forms – AnKing Dec 06 '18 at 18:08
  • Can you please provide a short example of what you mean? Do you have control instances defined in library code? – Rufus L Dec 06 '18 at 18:10
  • @RufusL I have dialogs - System.Windows.Forms.MessageBox.Show() in winforms implementation – AnKing Dec 06 '18 at 18:11
  • Got it. I don't know the short answer, but the long answer is to separate the logic from the UI. That code will not be very maintainable as it grows. – Rufus L Dec 06 '18 at 18:15
  • At the very least you should probably implement a logging class that you call for logging all messages, so that you don't have a bunch of duplicate methods and `if` statements scattered about. – Rufus L Dec 06 '18 at 18:17
  • @RufusL I agree that the long answer is the most appropriate way to go, but for now I'm just looking for a short solution because making changes in winforms app aren't feasible. – AnKing Dec 06 '18 at 18:18

0 Answers0