This is feasible using Dependency Injection.
For instance, you may use contextual binding with Ninject to inject the appropriate type implementation so that this method call shall do nothing whilst another implementation shall do what is intended.
public abstract class MyBaseClass {
public abstract void MyMethod() { }
}
public class MyDerivedDotNet45Class : MyBaseclass() {
public override void MyMethod() { // Does something... }
}
public class MyDerivedWindowsPhoneClass : MyBaseClass() {
public override void MyMethod() { // Does nothing... }
}
public class MyWorkingProcessClass {
public MyWorkingProcessClass(MyBaseClass baseClass) {
dependency = baseClass;
}
public void MethodThatShallDoSomethingOnlyWhenDotNet45() {
dependency.MyMethod();
}
private readonly MyBaseClass dependency;
}
So depending on which class you inject, your program shall either do something or nothing.
Under .Net 4.5
var workingClass = new MyWorkingProcessClass(new MyDerivedDotNet45Class());
wokringClass.MethodThatShallDoSomethingOnlyWhenDotNet45();
This shall do something as stated in the derived class.
Under Windows Phone
var workingClass = new MyWorkingProcessClass(new MyDerivedWindowsPhoneClass());
workingClass.MethodThatShallDoSomethingOnlyWhenDotNet45();
This shall do nothing as stated in the derived class.
Using Ninject
This answer provides with a good example of using Contextual Binding.
This is in the Composition Root that you shall build your object composition so that it knows what to inject where and when.