Is there a way to detect the calling platform in C#?
In my scenario OnPropertyChanged
should only be called if the platform is WPF. Our ASP.NET application should not use this method.
Is there a way to detect the calling platform in C#?
In my scenario OnPropertyChanged
should only be called if the platform is WPF. Our ASP.NET application should not use this method.
The way you have phrased your question makes it sound like you have a code smell.
If you are using common data objects, then they should not discriminate between the platforms that use them. OnPropertyChanged
normally just raises the PropertyChanged
event - nothing more, and the consuming platform shouldn't care. If the consuming platform hasn't registered a handler for the event then it will be oblivious to the raising of the event.
One possibility to consider is that if the data entities are compiled as part of the calling platform (i.e. they are not in a common assembly referenced by both) then you could use compile time #defines.
You can check the HttpRuntime.AppDomainAppId Property:
if(HttpRuntime.AppDomainAppId != null)
{
//if it's not null it is a web app
}
else
{
//if it's null it is a desktop app
}