Beispiel #1
0
        protected override MethodBuilder CreateMethodBuilder(TypeBuilder typeBuilder, NativeIlGenContext context)
        {
            // Find the native.
            var sizes = context.Parameters
                        .Select(p => p.LengthParam)
                        .Where(p => p != null)
                        .Select(p => (uint)p.Index)
                        .ToArray();
            var types = context.Parameters
                        .Select(p => p.InputType)
                        .ToArray();
            var native = _nativeLoader.Load(context.NativeName, sizes, types);

            if (native == null)
            {
                return(null);
            }

            // Generate the method body.
            var methodBuilder = typeBuilder.DefineMethod(context.BaseMethod.Name, context.MethodOverrideAttributes, context.BaseMethod.ReturnType, context.MethodParameterTypes);

            Generate(methodBuilder.GetILGenerator(), context, native);

            return(methodBuilder);
        }
        protected override MethodBuilder CreateMethodBuilder(string nativeName, Type proxyType, uint[] nativeArgumentLengths,
                                                             TypeBuilder typeBuilder, MethodInfo method, string[] identifierPropertyNames, int idIndex, FieldInfo[] proxyFields)
        {
            // Define the method.
            var idCount = identifierPropertyNames.Length;

            var attributes           = GetMethodOverrideAttributes(method);
            var parameterTypes       = GetMethodParameters(method);
            var nativeParameterTypes = GetNativeParameters(parameterTypes, idIndex, idCount);

            // Find the native.
            var native = _nativeLoader.Load(nativeName, nativeArgumentLengths, nativeParameterTypes);

            if (native == null)
            {
                return(null);
            }

            // Generate the method body.
            var methodBuilder = typeBuilder.DefineMethod(method.Name, attributes, method.ReturnType, parameterTypes);

            var gen = new NativeHandleBasedProxyGenerator(native, proxyType, identifierPropertyNames, 0, parameterTypes, method.ReturnType);

            gen.Generate(methodBuilder.GetILGenerator());

            return(methodBuilder);
        }
 /// <summary>
 ///     Loads a native with the specified name.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="sizes">The references to the parameter which contains the size of array parameters.</param>
 /// <param name="parameterTypes">The parameter types.</param>
 /// <returns>The loaded native.</returns>
 public static INative Load(string name, int[] sizes, params Type[] parameterTypes)
 {
     return(_nativeLoader.Load(name, sizes, parameterTypes));
 }