コード例 #1
0
        public DynamicLib(string fileName, DLOpenMode flags)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            if (flags == DLOpenMode.None)
            {
                throw new ArgumentOutOfRangeException(nameof(flags));
            }

            string selfPath = Path.GetDirectoryName(typeof(DynamicLib).Assembly.Location);

            string [] possibleFiles = new string [] {
                fileName,
                Path.Combine(selfPath, Path.Combine($"Frameworks/{fileName}.framework/{fileName}"))
            };

            var sb = new StringBuilder();

            foreach (string file in possibleFiles)
            {
                FileName = file;
                handle   = DLOpen(file, flags);
                if (handle == IntPtr.Zero)
                {
                    sb.Append('\n');
                    sb.Append($"+{file} {(File.Exists (file) ? "(exists)" : " (does not exist)")}");
                    string err = DLError;
                    if (err != null)
                    {
                        sb.Append(": ");
                        sb.Append(err);
                    }
                }
                else
                {
                    break;
                }
            }
            if (handle == IntPtr.Zero)
            {
                string sbbuff = sb.ToString();
                throw new ArgumentException($"Unable to load library {fileName}:{sbbuff}", nameof(fileName));
            }
        }
コード例 #2
0
 static extern IntPtr DLOpen([MarshalAs(UnmanagedType.LPStr)] string file, DLOpenMode flags);
コード例 #3
0
 internal static IntPtr ProtocolWitnessTableFromDylibFile(string path, DLOpenMode mode, string witnessSymbolName)
 {
     using (DynamicLib lib = new DynamicLib(path, mode)) {
         return(ProtocolWitnessTableFromDylib(lib, witnessSymbolName));
     }
 }
コード例 #4
0
 internal static SwiftValueWitnessTable FromDylibFile(string path, DLOpenMode mode, string witnessSymbolName)
 {
     using (DynamicLib lib = new DynamicLib(path, mode)) {
         return(FromDylib(lib, witnessSymbolName));
     }
 }
コード例 #5
0
 internal static SwiftMetatype?FromDylib(string pathName, DLOpenMode openMode, string metaDescName)
 {
     using (DynamicLib dylib = new DynamicLib(pathName, openMode)) {
         return(FromDylib(dylib, metaDescName));
     }
 }
コード例 #6
0
 internal static SwiftNominalTypeDescriptor?FromDylibFile(string pathName, DLOpenMode openMode, string nomDescSymbolName)
 {
     using (DynamicLib dylib = new DynamicLib(pathName, openMode)) {
         return(FromDylib(dylib, nomDescSymbolName));
     }
 }
コード例 #7
0
 public static NominalSizeStride FromDylibFile(string file, DLOpenMode mode, string witnessTableName)
 {
     using (DynamicLib lib = new DynamicLib(file, mode)) {
         return(FromDylib(lib, witnessTableName));
     }
 }