コード例 #1
0
        /// <summary>
        ///     Loads library in a platform specific way.
        /// </summary>
        static IntPtr PlatformSpecificLoadLibrary(string libraryPath)
        {
            if (IsWindows)
            {
                return(Windows.LoadLibrary(libraryPath));
            }
            if (IsLinux)
            {
                if (IsMono)
                {
                    return(Mono.dlopen(libraryPath, RTLD_GLOBAL + RTLD_LAZY));
                }
                if (IsNetCore)
                {
                    return(CoreCLR.dlopen(libraryPath, RTLD_GLOBAL + RTLD_LAZY));
                }
                return(Linux.dlopen(libraryPath, RTLD_GLOBAL + RTLD_LAZY));
            }

            if (IsMacOSPlatform)
            {
                return(MacOSX.dlopen(libraryPath, RTLD_GLOBAL + RTLD_LAZY));
            }
            throw new InvalidOperationException("Unsupported platform.");
        }
コード例 #2
0
        static NativeLibrary()
        {
            const int RTLD_NOW = 2;

            if (Platform.IsWindows)
            {
                Open      = Windows.LoadLibrary;
                GetSymbol = Windows.GetProcAddress;
            }
            else if (Platform.IsOSX)
            {
                Open      = f => OSX.dlopen(f, RTLD_NOW);
                GetSymbol = OSX.dlsym;
            }
            else if (Platform.IsLinux)
            {
                if (Platform.IsMono)
                {
                    Open      = f => Mono.dlopen(f, RTLD_NOW);
                    GetSymbol = Mono.dlsym;
                }
                else if (Platform.IsNetCore)
                {
                    Open      = f => CoreCLR.dlopen(f, RTLD_NOW);
                    GetSymbol = CoreCLR.dlsym;
                }
                else
                {
                    Open      = f => Linux.dlopen(f, RTLD_NOW);
                    GetSymbol = Linux.dlsym;
                }
            }
            else
            {
                throw new PlatformNotSupportedException();
            }
        }