本文整理汇总了C#中System.Reflection.Module.GetMethods方法的典型用法代码示例。如果您正苦于以下问题:C# Module.GetMethods方法的具体用法?C# Module.GetMethods怎么用?C# Module.GetMethods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Module
的用法示例。
在下文中一共展示了Module.GetMethods方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterModule
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);
}
}
示例2: MethodsModule
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);
}
}
示例3: EmitSource
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)
//.........这里部分代码省略.........