BananaHook.Infrastructure.Helper.ThrowWin32ExceptionIfFalse C# (CSharp) Method

ThrowWin32ExceptionIfFalse() public static method

public static ThrowWin32ExceptionIfFalse ( Func func ) : void
func Func
return void
        public static void ThrowWin32ExceptionIfFalse(Func<bool> func)
        {
            if (!func())
                throw new Win32Exception(Marshal.GetLastWin32Error());
        }

Usage Example

Beispiel #1
0
        public void ExecuteWithProtection(MemoryProtectionConstraints requestedProtection, Action action)
        {
            MemoryProtectionConstraints oldProtection = MemoryProtectionConstraints.None;

            Helper.ThrowWin32ExceptionIfFalse(() =>
                                              _protection.VirtualProtect(_address, _length, requestedProtection, out oldProtection));

            try
            {
                action();
            }
            finally
            {
                Helper.ThrowWin32ExceptionIfFalse(() =>
                                                  _protection.VirtualProtect(_address, _length, oldProtection, out oldProtection));
            }
        }