I have a class that needs to run in both Silverlight and non-Silverlight runtimes. However, the behavior is slightly different so I need something like…
if(isRunningInSilverlight) {
// do this
} else {
// do that
}
How do I correctly assign isRunningInSilverlight?
Considering that different compilers are used to create Silverlight and non-Silverlight assemblies, you could use compiler directives and conditionally compile your code rather than detect the difference at runtime. Just define
SILVERLIGHT(or some other define) for the Silverlight build and then have:You could use the
ConditionalAttributeas well with this approach.