GetMethods() public method

public GetMethods ( ) : System.Reflection.MethodInfo[]
return System.Reflection.MethodInfo[]
Esempio n. 1
0
 public static void RegisterModule(Module module)
 {
     if (module == null)
         throw new ArgumentNullException("module");
     foreach (Type type in module.GetTypes())
     {
         RegisterType(type);
     }
     foreach (MethodInfo method in module.GetMethods())
     {
         RegisterMethod(method);
     }
 }
Esempio n. 2
0
			public MethodsModule(Module module) {
				var flags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

				foreach (var type in module.GetTypes()) {
					if (methods.Count >= MAX_METHODS)
						break;
					foreach (var method in type.GetMethods(flags)) {
						if (methods.Count >= MAX_METHODS)
							break;
						methods.Add(method);
					}
				}

				foreach (var method in module.GetMethods(flags)) {
					if (methods.Count >= MAX_METHODS)
						break;
					methods.Add(method);
				}
			}
Esempio n. 3
0
        private static TypeBuilder[] EmitSource(Module module, ModuleBuilder moduleB, Set replacedMethods, MetaDataMapper mapper)
        {
            ModuleEx moduleEx = new ModuleEx(module);

            ArrayList allMethods = new ArrayList();
            ArrayList allCtors = new ArrayList();
            ArrayList allTypes = new ArrayList();

            Hashtable map = mapper.MapTable;
            //FieldInfo -> FieldBuilder, MethodInfo -> MethodBuilder... mapping
            //Type -> Type mapping is performed through moduleB.GetType(), because of array & ref types

            Type[] types = module.GetTypes();
            Sort(types);

            foreach(Type type in types)
            {
                TypeBuilder typeB;
                if(type.DeclaringType != null)
                {
                    typeB = (mapper.Map(type.DeclaringType) as TypeBuilder).DefineNestedType(type.Name, type.Attributes, mapper.Map(type.BaseType), mapper.Map(GetDeclaredInterfaces(type)));
                    //Don't know how to declare nested enums :((
                    //Anyway, "nested-value-types BUG" affects them, too
                }
                else
                {
                    typeB = moduleB.DefineType(type.FullName, type.Attributes, mapper.Map(type.BaseType), mapper.Map(GetDeclaredInterfaces(type)));
                }
                allTypes.Add(typeB);
            }

            //The end of type declarations...
            foreach(Type type in types)
            {
                TypeBuilder typeB = mapper.Map(type) as TypeBuilder;
                FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly);
                foreach(FieldInfo field in fields)
                {
                    if(field.IsLiteral)
                        continue; //Andrew: ZLP
               				    FieldAttributes attributes = AddInternalAttribute(field.Attributes);
                    FieldBuilder fieldB = typeB.DefineField(field.Name, mapper.Map(field.FieldType), attributes);
                    map[field] = fieldB;
                }

                PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly);
                foreach(PropertyInfo property in properties)
                {
                    ParameterInfo[] parameters = property.GetIndexParameters();
                    Type[] paramTypes = new Type[parameters.Length];
                    for(int i=0; i<paramTypes.Length; i++)
                        paramTypes[i] = mapper.Map( parameters[i].ParameterType);
                    PropertyBuilder propertyB = typeB.DefineProperty(property.Name, property.Attributes, mapper.Map(property.PropertyType), paramTypes);
                    map[property] = propertyB;
                }

                EventInfo[] events = type.GetEvents(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly);
                foreach(EventInfo Event in events)
                {
                    EventBuilder eventB = typeB.DefineEvent(Event.Name, Event.Attributes, mapper.Map(Event.EventHandlerType));
                    map[Event] = eventB;
                }

                MethodInfo[] methods = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly);
                foreach(MethodInfo method in methods)
                {
                    ParameterInfo[] parameters = method.GetParameters();
                    Type[] paramTypes = new Type[parameters.Length];
                    for(int i=0; i<paramTypes.Length; i++)
                        paramTypes[i] = mapper.Map( parameters[i].ParameterType);
                    MethodAttributes attributes = AddInternalAttribute(method.Attributes);
                    MethodBuilder methodB = typeB.DefineMethod(method.Name, attributes, method.CallingConvention, mapper.Map(method.ReturnType), paramTypes);
                    for(int i=0; i<paramTypes.Length; i++)
                        methodB.DefineParameter(i+1, parameters[i].Attributes, parameters[i].Name);
                    map[method] = methodB;
                    if(!replacedMethods.Contains(method))
                        allMethods.Add(method);
                }

                ConstructorInfo[] ctors = type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly);
                foreach(ConstructorInfo ctor in ctors)
                {
                    ParameterInfo[] parameters = ctor.GetParameters();
                    Type[] paramTypes = new Type[parameters.Length];
                    for(int i=0; i<paramTypes.Length; i++)
                        paramTypes[i] = mapper.Map( parameters[i].ParameterType);
                    MethodAttributes attributes = AddInternalAttribute(ctor.Attributes);
                    ConstructorBuilder ctorB = typeB.DefineConstructor(attributes, ctor.CallingConvention, paramTypes);
                    for(int i=0; i<paramTypes.Length; i++)
                        ctorB.DefineParameter(i+1, parameters[i].Attributes, parameters[i].Name);
                    map[ctor] = ctorB;
                    if(!replacedMethods.Contains(ctor))
                        allCtors.Add(ctor);
                }
                if(type.IsValueType)
                    typeB.DefineDefaultConstructor(MethodAttributes.Public);
            }//foreach type

            MethodInfo[] globalMethods = module.GetMethods();
            foreach(MethodInfo method in globalMethods)
            {
                ParameterInfo[] parameters = method.GetParameters();
                Type[] paramTypes = new Type[parameters.Length];
                for(int i=0; i<paramTypes.Length; i++)
                    paramTypes[i] = mapper.Map( parameters[i].ParameterType);
                MethodAttributes attributes = AddInternalAttribute(method.Attributes);
                MethodBuilder methodB = moduleB.DefineGlobalMethod(method.Name, attributes, method.CallingConvention, mapper.Map(method.ReturnType), paramTypes);
                for(int i=0; i<paramTypes.Length; i++)
                    methodB.DefineParameter(i+1, parameters[i].Attributes, parameters[i].Name);
                map[method] = methodB;
                if(!replacedMethods.Contains(method))
                    allMethods.Add(method);
            }

            //The end of fields, methods, ctors declarations...

            foreach(MethodInfo method in allMethods)
            {
                ILGenerator generator = (mapper.Map(method) as MethodBuilder).GetILGenerator();
                ProcessMethod(generator, moduleEx.GetMethodEx(method), method, mapper);
            }

            foreach(ConstructorInfo ctor in allCtors)
            {
                ILGenerator generator = (mapper.Map(ctor) as ConstructorBuilder).GetILGenerator();
                ProcessMethod(generator, moduleEx.GetMethodEx(ctor), ctor, mapper);
            }

            TypeBuilder[] result = new TypeBuilder[allTypes.Count];
            allTypes.CopyTo(result);
            return(result);
        }