static Unsafe() { #if Mono #else try { if (System.Environment.Is64BitProcess) { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x64.dll"); } else { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x86.dll"); } _copy = _nativeLibraryManager.GetMethod<CopyDelegate>("copy"); _equals = _nativeLibraryManager.GetMethod<EqualsDelegate>("equals"); _compare = _nativeLibraryManager.GetMethod<CompareDelegate>("compare"); _xor = _nativeLibraryManager.GetMethod<XorDelegate>("xor"); } catch (Exception e) { Log.Warning(e); } #endif }
private FileMode(int mode, ObjectType type, EqualsDelegate equals) { if (equals == null) throw new ArgumentNullException("equals"); this.Equals = equals; this.Bits = mode; this.ObjectType = type; if (mode != 0) { byte[] tmp = new byte[10]; int p = tmp.Length; while (mode != 0) { tmp[--p] = (byte)('0' + (mode & 07)); mode >>= 3; } _octalBytes = new byte[tmp.Length - p]; for (int k = 0; k < _octalBytes.Length; k++) { _octalBytes[k] = tmp[p + k]; } } else { _octalBytes = new byte[] { (byte)'0' }; } }
static Unsafe() { #if Mono #else try { if (System.Environment.Is64BitProcess) { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x64.dll"); } else { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x86.dll"); } _copy = _nativeLibraryManager.GetMethod <CopyDelegate>("copy"); _equals = _nativeLibraryManager.GetMethod <EqualsDelegate>("equals"); _compare = _nativeLibraryManager.GetMethod <CompareDelegate>("compare"); _xor = _nativeLibraryManager.GetMethod <XorDelegate>("xor"); } catch (Exception e) { Log.Warning(e); } #endif }
private FileMode(int mode, ObjectType type, EqualsDelegate equals) { if (equals == null) { throw new ArgumentNullException("equals"); } this.Equals = equals; this.Bits = mode; this.ObjectType = type; if (mode != 0) { byte[] tmp = new byte[10]; int p = tmp.Length; while (mode != 0) { tmp[--p] = (byte)('0' + (mode & 07)); mode >>= 3; } _octalBytes = new byte[tmp.Length - p]; for (int k = 0; k < _octalBytes.Length; k++) { _octalBytes[k] = tmp[p + k]; } } else { _octalBytes = new byte[] { (byte)'0' }; } }
internal static void LoadPureUnsafeMethods() { _zero = PureUnsafeMethods.Zero; _copy = PureUnsafeMethods.Copy; _equals = PureUnsafeMethods.Equals; _compare = PureUnsafeMethods.Compare; _and = PureUnsafeMethods.And; _or = PureUnsafeMethods.Or; _xor = PureUnsafeMethods.Xor; }
/// <summary> /// Creates a new equality comparer. /// </summary> public DelegateEqualityComparer(GetHashCodeDelegate hashCodeDelegate, EqualsDelegate equalsDelegate) { if (hashCodeDelegate == null) { throw new ArgumentNullException("hashCodeDelegate"); } if (equalsDelegate == null) { throw new ArgumentNullException("equalsDelegate"); } _equalsDelegate = equalsDelegate; _hashCodeDelegate = hashCodeDelegate; }
internal static void LoadNativeMethods() { _nativeLibraryManager?.Dispose(); try { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (RuntimeInformation.ProcessArchitecture == Architecture.X64) { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Omnix.Base.win-x64.dll"); } else { throw new NotSupportedException(); } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { if (RuntimeInformation.ProcessArchitecture == Architecture.X64) { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Omnix.Base.linux-x64.so"); } else { throw new NotSupportedException(); } } else { throw new NotSupportedException(); } _zero = _nativeLibraryManager.GetMethod <ZeroDelegate>("zero"); _copy = _nativeLibraryManager.GetMethod <CopyDelegate>("copy"); _equals = _nativeLibraryManager.GetMethod <EqualsDelegate>("equals"); _compare = _nativeLibraryManager.GetMethod <CompareDelegate>("compare"); _and = _nativeLibraryManager.GetMethod <BitwiseOperationDelegate>("math_and"); _or = _nativeLibraryManager.GetMethod <BitwiseOperationDelegate>("math_or"); _xor = _nativeLibraryManager.GetMethod <BitwiseOperationDelegate>("math_xor"); } catch (Exception) { _nativeLibraryManager?.Dispose(); _nativeLibraryManager = null; throw; } }
static Unsafe() { try { #if Windows if (System.Environment.Is64BitProcess) { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x64.dll"); } else { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x86.dll"); } #endif #if Unix if (System.Environment.Is64BitProcess) { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x64.so"); } else { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x86.so"); } #endif _copy = _nativeLibraryManager.GetMethod<CopyDelegate>("copy"); _equals = _nativeLibraryManager.GetMethod<EqualsDelegate>("equals"); _compare = _nativeLibraryManager.GetMethod<CompareDelegate>("compare"); _and = _nativeLibraryManager.GetMethod<BitwiseOperationDelegate>("math_and"); _or = _nativeLibraryManager.GetMethod<BitwiseOperationDelegate>("math_or"); _xor = _nativeLibraryManager.GetMethod<BitwiseOperationDelegate>("math_xor"); } catch (Exception e) { Log.Warning(e); } }
protected TFolderItem FindItem <TId>(EqualsDelegate <TId> isItem, TId id, bool recursive) { foreach (TFolderItem item in _items) { if (isItem(item, id)) { return(item); } } if (recursive) { foreach (TFolder subFolder in this.SubFolders) { TFolderItem found = subFolder.FindItem <TId>(isItem, id, recursive); if (found != null) { return(found); } } } return(default(TFolderItem)); }
private static unsafe void ManagedFunctionPointer() { { EqualsDelegate equalsFunc = Program.Equals; equalsFunc(1, 2); } { Func <int, int, bool> equalsFunc = Program.Equals; equalsFunc(1, 2); } { delegate * < int, int, bool > equalsFunc = &Program.Equals; equalsFunc(1, 2); delegate * managed <string, void> writeLineFunc = null; writeLineFunc = &Program.WriteLine; writeLineFunc("1 == 2: " + equalsFunc(1, 2)); } { IntPtr pFunc = new IntPtr(1000); delegate * < void > unsafeFunc = (delegate * < void >)pFunc; // Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. // unsafeFunc(); } { delegate * < string, void > writeLineFunc = &Program.WriteLine; IntPtr ptr = new IntPtr(writeLineFunc); delegate * < void > unsafeFunc = (delegate * < void >)ptr; // Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. // unsafeFunc(); } }
public DynamicEqualityComparer(EqualsDelegate <T> equalityMethod, GetHashCodeDelegate <T> hashcodeMethod) { EqualityMethod = equalityMethod; GetHashCodeMethod = hashcodeMethod; }
/// <summary> /// Constructs a new <see cref="DelegateEqualityComparer{T}"/> with the provided <paramref name="hashDelegate"/> and <paramref name="equalsDelegate"/> delegates. /// </summary> /// <param name="hashDelegate">A function to compute a hash code for a given <typeparamref name="T"/>.</param> /// <param name="equalsDelegate">A function to compare two <typeparamref name="T"/>s.</param> public DelegateEqualityComparer(HashDelegate hashDelegate, EqualsDelegate equalsDelegate) { this._hashDelegate = hashDelegate; this._equalsDelegate = equalsDelegate; }