示例#1
0
        /// <summary>
        /// Get a method from a managed type, method name and argument count
        /// </summary>
        public static MethodInfo GetFromName(Process process, System.Type type, string name, int paramCount)
        {
            if (type.IsNested)
            {
                throw new DebuggerException("Not implemented for nested types");
            }
            if (type.IsGenericType)
            {
                throw new DebuggerException("Not implemented for generic types");
            }
            if (type.IsGenericParameter)
            {
                throw new DebuggerException("Type can not be generic parameter");
            }

            foreach (Module module in process.Modules)
            {
                TypeDefProps typeDefProps;
                try
                {
                    typeDefProps = module.MetaData.FindTypeDefByName(type.FullName, 0 /* enclosing class for nested */);
                }
                catch
                {
                    continue;
                }
                foreach (MethodProps methodProps in module.MetaData.EnumMethodsWithName(typeDefProps.Token, name))
                {
                    if (module.MetaData.GetParamCount(methodProps.Token) == paramCount)
                    {
                        ICorDebugFunction corFunction = module.CorModule.GetFunctionFromToken(methodProps.Token);
                        ICorDebugClass2   corClass    = corFunction.Class.As <ICorDebugClass2>();
                        ICorDebugType     corType     = corClass.GetParameterizedType(type.IsValueType ? (uint)CorElementType.VALUETYPE : (uint)CorElementType.CLASS,
                                                                                      0,
                                                                                      new ICorDebugType[] {});
                        return(new MethodInfo(DebugType.Create(process, corType), methodProps));
                    }
                }
            }
            throw new DebuggerException("Not found");
        }
示例#2
0
        // ICorDebugClass2

        public static ICorDebugType GetParameterizedType(this ICorDebugClass2 corClass, uint elementType, ICorDebugType[] ppTypeArgs)
        {
            return(corClass.GetParameterizedType(elementType, (uint)ppTypeArgs.Length, ppTypeArgs));
        }