Exemple #1
0
        static Native()
        {
            var staticMethods = typeof(Buffer)
                                .GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).ToArray();

            var bufferMemCpyMethods = staticMethods
                                      .Where(mi => mi.Name == "Memcpy").ToArray();

            MemcpyFromUnmanaged =
                (MemcpyFromUnmanagedDelegate)
                Delegate.CreateDelegate(typeof(MemcpyFromUnmanagedDelegate), bufferMemCpyMethods.Single(mi =>
            {
                var parameters = mi.GetParameters();
                return(parameters.Length == 5 && parameters[0].ParameterType == typeof(byte[]));
            }));

            MemcpyToUnmanaged =
                (MemcpyToUnmanagedDelegate)
                Delegate.CreateDelegate(typeof(MemcpyToUnmanagedDelegate), bufferMemCpyMethods.Single(mi =>
            {
                var parameters = mi.GetParameters();
                return(parameters.Length == 5 && parameters[0].ParameterType == typeof(byte *));
            }));

            MemcpyUnmanaged =
                (MemcpyUnmanagedDelegate)
                Delegate.CreateDelegate(typeof(MemcpyUnmanagedDelegate),
                                        bufferMemCpyMethods.Single(mi => mi.GetParameters().Length == 3));

            ZeroMemory =
                (ZeroMemoryDelegate)
                Delegate.CreateDelegate(typeof(ZeroMemoryDelegate),
                                        staticMethods.Single(mi => mi.Name == "ZeroMemory"));

            GetSystemInfo(out Info);
        }
Exemple #2
0
        static Native()
        {
            var staticMethods = typeof (Buffer)
                .GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).ToArray();

            var bufferMemCpyMethods = staticMethods
                .Where(mi => mi.Name == "Memcpy").ToArray();

            MemcpyFromUnmanaged =
                (MemcpyFromUnmanagedDelegate)
                    Delegate.CreateDelegate(typeof (MemcpyFromUnmanagedDelegate), bufferMemCpyMethods.Single(mi =>
                    {
                        var parameters = mi.GetParameters();
                        return parameters.Length == 5 && parameters[0].ParameterType == typeof (byte[]);
                    }));

            MemcpyToUnmanaged =
                (MemcpyToUnmanagedDelegate)
                    Delegate.CreateDelegate(typeof (MemcpyToUnmanagedDelegate), bufferMemCpyMethods.Single(mi =>
                    {
                        var parameters = mi.GetParameters();
                        return parameters.Length == 5 && parameters[0].ParameterType == typeof (byte*);
                    }));

            MemcpyUnmanaged =
                (MemcpyUnmanagedDelegate)
                    Delegate.CreateDelegate(typeof (MemcpyUnmanagedDelegate),
                        bufferMemCpyMethods.Single(mi => mi.GetParameters().Length == 3));

            ZeroMemory =
                (ZeroMemoryDelegate)
                    Delegate.CreateDelegate(typeof (ZeroMemoryDelegate),
                        staticMethods.Single(mi => mi.Name == "ZeroMemory"));

            GetSystemInfo(out Info);
        }