public void CreateDelegateFromStaticMethodByName() { Action action = Delegates.CreateDelegate <Action>(GetType(), "StaticActionMethod"); Action expected = StaticActionMethod; Assert.AreEqual(expected, action); }
public void CreateDelegateFromStaticMethodByNameCaseInsensitively() { Action action = Delegates.CreateDelegate <Action>(GetType(), "staticactionmethod", true); Action expected = StaticActionMethod; Assert.AreEqual(expected, action); }
public void CreateDelegateFromInstanceMethodByName() { Action action = Delegates.CreateDelegate <Action>(this, "InstanceActionMethod"); Action expected = InstanceActionMethod; Assert.AreEqual(expected, action); }
public void CreateDelegateFromInstanceMethodByNameCaseInsensitively() { Action action = Delegates.CreateDelegate <Action>(this, "INSTANCEACTIONMETHOD", true); Action expected = InstanceActionMethod; Assert.AreEqual(expected, action); }
/// <summary> /// CreateFile wrapper that attempts to use CreateFile2 if running as Windows Store app. /// </summary> public static SafeFileHandle CreateFile( StringSpan path, CreationDisposition creationDisposition, DesiredAccess desiredAccess = DesiredAccess.GenericReadWrite, ShareModes shareMode = ShareModes.ReadWrite, FileAttributes fileAttributes = FileAttributes.None, FileFlags fileFlags = FileFlags.None, SecurityQosFlags securityQosFlags = SecurityQosFlags.None) { // Prefer CreateFile2, falling back to CreateFileEx if we can if (s_createFileDelegate == null) { s_createFileDelegate = CreateFile2; try { return(s_createFileDelegate(path, desiredAccess, shareMode, creationDisposition, fileAttributes, fileFlags, securityQosFlags)); } catch (EntryPointNotFoundException) { s_createFileDelegate = Delegates.CreateDelegate <CreateFileDelegate>( "WInterop.Storage.Desktop.NativeMethods, " + Delegates.DesktopLibrary, "CreateFileW"); } } return(s_createFileDelegate(path, desiredAccess, shareMode, creationDisposition, fileAttributes, fileFlags, securityQosFlags)); }
/// <summary> /// CopyFile wrapper that attempts to use CopyFile2 if running as Windows Store app. /// </summary> public static void CopyFile(string source, string destination, bool overwrite = false) { // Prefer CreateFile2, falling back to CreateFileEx if we can if (s_copyFileDelegate == null) { s_copyFileDelegate = CopyFile2; try { s_copyFileDelegate(source, destination, overwrite); return; } catch (Exception exception) { // Any error other than EntryPointNotFound we've found CreateFile2, rethrow if (!ErrorHelper.IsEntryPointNotFoundException(exception)) { throw; } s_copyFileDelegate = Delegates.CreateDelegate <CopyFileDelegate>( "WInterop.FileManagement.Desktop.NativeMethods, " + Delegates.DesktopLibrary, "CopyFileEx"); } } s_copyFileDelegate(source, destination, overwrite); }
/// <summary> /// CreateFile wrapper that attempts to use CreateFile2 if running as Windows Store app. /// </summary> public static SafeFileHandle CreateFile( string path, DesiredAccess desiredAccess, ShareMode shareMode, CreationDisposition creationDisposition, FileAttributes fileAttributes = FileAttributes.NONE, FileFlags fileFlags = FileFlags.NONE, SecurityQosFlags securityQosFlags = SecurityQosFlags.NONE) { // Prefer CreateFile2, falling back to CreateFileEx if we can if (s_createFileDelegate == null) { s_createFileDelegate = CreateFile2; try { return(s_createFileDelegate(path, desiredAccess, shareMode, creationDisposition, fileAttributes, fileFlags, securityQosFlags)); } catch (Exception exception) { // Any error other than EntryPointNotFound we've found CreateFile2, rethrow if (!ErrorHelper.IsEntryPointNotFoundException(exception)) { throw; } s_createFileDelegate = Delegates.CreateDelegate <CreateFileDelegate>( "WInterop.FileManagement.Desktop.NativeMethods, " + Delegates.DesktopLibrary, "CreateFileW"); } } return(s_createFileDelegate(path, desiredAccess, shareMode, creationDisposition, fileAttributes, fileFlags, securityQosFlags)); }
public void SimpleGetDelegate() { var beginsWithDirectorySeparator = Delegates.CreateDelegate <SpanToBool>(@"WInterop.Support.Paths, " + Delegates.DesktopLibrary, "BeginsWithDirectorySeparator"); beginsWithDirectorySeparator.Should().NotBeNull(); beginsWithDirectorySeparator(@"a").Should().BeFalse(); beginsWithDirectorySeparator(@"\a").Should().BeTrue(); }
public void SimpleGetDelegate() { var endsInDirectorySeparator = Delegates.CreateDelegate <StringToBool>(@"WInterop.Support.Paths, " + Delegates.DesktopLibrary, "EndsInDirectorySeparator"); endsInDirectorySeparator.Should().NotBeNull(); endsInDirectorySeparator(@"a").Should().BeFalse(); endsInDirectorySeparator(@"a\").Should().BeTrue(); }
public void CreateDelegateFromInstanceMethod() { MethodInfo method = typeof(DelegatesTest).GetMethod("InstanceActionMethod"); Action action = Delegates.CreateDelegate <Action>(this, method); Action expected = InstanceActionMethod; Assert.AreEqual(expected, action); }
public void CreateDelegateFromStaticMethod() { MethodInfo method = typeof(DelegatesTest).GetMethod("StaticActionMethod"); Action action = Delegates.CreateDelegate <Action>(method); Action expected = StaticActionMethod; Assert.AreEqual(expected, action); }
/// <summary> /// CopyFile wrapper that attempts to use CopyFile2 if running as Windows Store app. /// </summary> public static void CopyFile(string source, string destination, bool overwrite = false) { // Prefer CreateFile2, falling back to CreateFileEx if we can if (s_copyFileDelegate == null) { s_copyFileDelegate = CopyFile2; try { s_copyFileDelegate(source, destination, overwrite); return; } catch (EntryPointNotFoundException) { s_copyFileDelegate = Delegates.CreateDelegate <CopyFileDelegate>( "WInterop.Storage.Desktop.NativeMethods, " + Delegates.DesktopLibrary, "CopyFileEx"); } } s_copyFileDelegate(source, destination, overwrite); }
public void CreateDelegateWithoutTargetSuppressingBindFailure() { MethodInfo method = typeof(DelegatesTest).GetMethod("InstanceActionMethod"); Assert.IsNull(Delegates.CreateDelegate <Action>(method, false)); }
public void CreateDelegateFromStaticMethodByNameCaseSensitively() { Assert.IsNull(Delegates.CreateDelegate <Action>(GetType(), "staticactionmethod", false, false)); }
public void CreateDelegateFromInstanceMethodByNameCaseSensitivelySuppressingBindFailure() { Assert.IsNull(Delegates.CreateDelegate <Action>(this, "INSTANCEACTIONMETHOD", false, false)); }