Пример #1
0
        DebugType(Process process, ICorDebugType corType)
        {
            if (corType == null)
            {
                throw new ArgumentNullException("corType");
            }

            this.process        = process;
            this.corType        = corType;
            this.corElementType = (CorElementType)corType.Type;

            if (this.IsClass || this.IsValueType)
            {
                this.module     = process.GetModule(corType.Class.Module);
                this.classProps = module.MetaData.GetTypeDefProps(corType.Class.Token);
            }

            if (this.IsClass || this.IsValueType || this.IsArray || this.IsPointer)
            {
                foreach (ICorDebugType t in corType.EnumerateTypeParameters().Enumerator)
                {
                    typeArguments.Add(DebugType.Create(process, t));
                }
            }

            this.fullName = GetName(true);
            this.name     = GetName(false);
        }
Пример #2
0
        /// <summary>
        /// Get a method from a managed type, method name and argument count
        /// </summary>
        public static MethodInfo GetFromName(Process process, uint?domainID, System.Type type, string methodName, 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");
            }

            DebugType debugType = DebugType.Create(process, domainID, type.FullName);

            if (debugType == null)
            {
                throw new DebuggerException("Type " + type.FullName + " not found");
            }

            foreach (MethodInfo methodInfo in debugType.GetMethods(methodName))
            {
                if (methodInfo.ParameterCount == paramCount)
                {
                    return(methodInfo);
                }
            }
            throw new DebuggerException("Method " + methodName + " not found");
        }
Пример #3
0
        void LoadMemberInfo()
        {
            // Load interfaces
            foreach (InterfaceImplProps implProps in module.MetaData.EnumInterfaceImplProps(this.Token))
            {
                if ((implProps.Interface & 0xFF000000) == (uint)CorTokenType.TypeDef ||
                    (implProps.Interface & 0xFF000000) == (uint)CorTokenType.TypeRef)
                {
                    this.interfaces.Add(DebugType.Create(module, implProps.Interface));
                }
            }

            // Load fields
            foreach (FieldProps field in module.MetaData.EnumFieldProps(this.Token))
            {
                if (field.IsStatic && field.IsLiteral)
                {
                    continue;                                                    // Skip static literals TODO: Why?
                }
                members.Add(new FieldInfo(this, field));
            }
            ;

            // Load methods
            foreach (MethodProps m in module.MetaData.EnumMethodProps(this.Token))
            {
                members.Add(new MethodInfo(this, m));
            }

            // Load properties
            // TODO: Handle indexers ("get_Item") in other code
            // Collect data
            Dictionary <string, MethodInfo> accessors     = new Dictionary <string, MethodInfo>();
            Dictionary <string, object>     propertyNames = new Dictionary <string, object>();

            foreach (MethodInfo method in this.GetMethods(BindingFlags.AllInThisType))
            {
                if (method.IsSpecialName && (method.Name.StartsWith("get_") || method.Name.StartsWith("set_")))
                {
                    // There can be many get_Items
                    // TODO: This returns only last, return all
                    accessors[method.Name] = method;
                    propertyNames[method.Name.Remove(0, 4)] = null;
                }
            }
            // Pair up getters and setters
            foreach (KeyValuePair <string, object> kvp in propertyNames)
            {
                MethodInfo getter = null;
                MethodInfo setter = null;
                accessors.TryGetValue("get_" + kvp.Key, out getter);
                accessors.TryGetValue("set_" + kvp.Key, out setter);
                members.Add(new PropertyInfo(this, getter, setter));
            }
        }
Пример #4
0
        /// <summary> Returns all non-generic types defined in the given module </summary>
        public static List <DebugType> GetDefinedTypesInModule(Module module)
        {
            // TODO: Generic types
            List <DebugType> types = new List <DebugType>();

            foreach (TypeDefProps typeDef in module.MetaData.EnumTypeDefProps())
            {
                if (module.MetaData.GetGenericParamCount(typeDef.Token) == 0)
                {
                    types.Add(DebugType.Create(module, typeDef.Token));
                }
            }
            return(types);
        }