Beispiel #1
0
        public NativeSignature GetNativeSignature(Guid id, bool ansiPlatform, bool platform64bit)
        {
            MethodInfo info;

            if (methodMap.TryGetValue(id, out info))
            {
                // requesting signature for a method
                if (NativeSignature.IsPInvoke(info))
                {
                    return(NativeSignature.FromPInvokeSignature(info, ansiPlatform, platform64bit));
                }
                else
                {
                    Debug.Assert(NativeSignature.IsRCWMethod(info));
                    return(NativeSignature.FromComInteropSignature(info, ansiPlatform, platform64bit));
                }
            }
            else
            {
                // requesting signature for a delegate
                Type type = typeMap[id];

                Debug.Assert(typeof(Delegate).IsAssignableFrom(type));
                return(NativeSignature.FromDelegateType(type, ansiPlatform, platform64bit));
            }
        }
Beispiel #2
0
        private static void GenerateMethod(MethodInfo method)
        {
            NativeSignature native_sig;

            Debug.WriteLine(method.DeclaringType.FullName + "::" + method.Name);

            if (NativeSignature.IsPInvoke(method))
            {
                // this is a P/Invoke method
                native_sig = NativeSignature.FromPInvokeSignature(
                    method,
                    options.TargetPlatformAnsi,
                    options.TargetPlatform64Bit);
            }
            else if (NativeSignature.IsRCWMethod(method))
            {
                // this is an RCW method
                native_sig = NativeSignature.FromComInteropSignature(
                    method,
                    options.TargetPlatformAnsi,
                    options.TargetPlatform64Bit);
            }
            else
            {
                ConsoleErrors.ERROR_MethodIsNotInterop.PrintTo(logPrinter, method.Name, method.DeclaringType.FullName);
                return;
            }

            PrintNativeSignature(native_sig);
        }
Beispiel #3
0
        /// <summary>
        /// Returns a list of interop (P/Invoke & RCW) method descriptors and list of delegates.
        /// </summary>
        public void GetInteropTypesAndMethods(out List <TypeDescriptor> typeDescs, out List <MethodDescriptor> methodDescs)
        {
            methodDescs = new List <MethodDescriptor>();
            typeDescs   = new List <TypeDescriptor>();

            // let's keep track of the types for which we have descriptors
            Dictionary <Type, TypeDescriptor> map = new Dictionary <Type, TypeDescriptor>();

            Type[] types;
            try
            {
                types = assembly.GetTypes();
            }
            catch (ReflectionTypeLoadException e)
            {
                // ReflectionTypeLoadException changes to FileNotFoundException when crossing the appdomain boundary
                // because it contain Type references to the target assembly -> convert to pure strings now
                throw new UnableToGetTypesException(e);
            }

            foreach (Type type in types)
            {
                TypeDescriptor type_desc = null;

                if (typeof(Delegate).IsAssignableFrom(type))
                {
                    type_desc = GetDescriptorForType(map, type);
                    typeDescs.Add(type_desc);
                }
                else
                {
                    foreach (MethodInfo info in type.GetMethods(bindingFlags))
                    {
                        if (NativeSignature.IsPInvoke(info) || NativeSignature.IsRCWMethod(info))
                        {
                            if (type_desc == null)
                            {
                                type_desc = GetDescriptorForType(map, type);
                            }

                            Guid             id          = Guid.NewGuid();
                            MethodDescriptor method_desc = new MethodDescriptor(this, info, type_desc, id);

                            methodDescs.Add(method_desc);
                            methodMap.Add(id, info);
                        }
                    }
                }
            }
        }
Beispiel #4
0
 private static void GenerateType(Type type)
 {
     if (typeof(Delegate).IsAssignableFrom(type))
     {
         GenerateDelegate(type);
     }
     else
     {
         foreach (MethodInfo mi in type.GetMethods(methodBindingFlags))
         {
             if (NativeSignature.IsPInvoke(mi) || NativeSignature.IsRCWMethod(mi))
             {
                 GenerateMethod(mi);
             }
         }
     }
 }