Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

XamMac conditional reference based on platform?

$
0
0

I'm guessing one of you will have a better answer for this than the more generic stuff I can dig up online.

The basic story is that I'm making heavy use of FileSystemWatcher, which works great on Windows and Linux. It turns out, the Mac implementation of FileSystemWatcher is basically nonfunctional (but no note is made of how bad its compatibility is), and the going suggestion is "don't use it, use FSEvents instead." Which, it turns out, isn't bad advice, the FSEvents API on Mac is really a fair bit better than FileSystemWatcher in general. The problem is, I have a bunch of business logic making use of FileSystemWatcher in my (supposed to be cross platform) general purpose assembly that all my platform-specific apps use. Somehow, I need to override that functionality, but only on mac (although I need to add some runtime code too to handle the Mac case, because there are some inconsistencies between .net FileSystemWatcher and FSEvents).

Anyway, my plan is to make an intermediate class, MyFileSystemWatcher, that behaves like a FileSystemWatcher and thus requires minimal changes to standing code, and I intend to do something like add a compile-time conditional:

# if MAC
    using BusinessLogic.Mac //.MyFileSystemWatcher
# else
    using BusinessLogic.General //.MyFileSystemWatcher
# endif

var fsWatcher = MyFileSystemWatcher(init_vars)

Of course, if I do that, it'll require that the project have a reference to the assembly containing BusinessLogic.Mac, which will have a reference to XamMac, which will break down when building on windows.

What's the best way to design around this?


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>