public static void SetFileManager(IFileManager fileManager) { if (fileManager != null) { _getCurrentDirectoryDelegate = fileManager.GetCurrentDirectory; _fileExistsDelegate = fileManager.FileExists; _isAbsolutePathDelegate = fileManager.IsAbsolutePath; _toAbsolutePathDelegate = fileManager.ToAbsolutePath; _readFileDelegate = fileManager.ReadFile; var delegates = new FileManagerDelegates { GetCurrentDirectoryDelegate = Marshal.GetFunctionPointerForDelegate(_getCurrentDirectoryDelegate), FileExistsDelegate = Marshal.GetFunctionPointerForDelegate(_fileExistsDelegate), IsAbsolutePathDelegate = Marshal.GetFunctionPointerForDelegate(_isAbsolutePathDelegate), ToAbsolutePathDelegate = Marshal.GetFunctionPointerForDelegate(_toAbsolutePathDelegate), ReadFileDelegate = Marshal.GetFunctionPointerForDelegate(_readFileDelegate) }; FileManagerMarshaller.SetDelegates(delegates); } else { UnsetFileManager(); } }
public static void UnsetFileManager() { FileManagerMarshaller.UnsetDelegates(); _getCurrentDirectoryDelegate = null; _fileExistsDelegate = null; _isAbsolutePathDelegate = null; _toAbsolutePathDelegate = null; _readFileDelegate = null; }