本文整理汇总了C#中System.Reflection.Module.GetTypes方法的典型用法代码示例。如果您正苦于以下问题:C# Module.GetTypes方法的具体用法?C# Module.GetTypes怎么用?C# Module.GetTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Module
的用法示例。
在下文中一共展示了Module.GetTypes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CollectErrorsOnMemberAndDescendents
private static IEnumerable<string> CollectErrorsOnMemberAndDescendents(Module module, IEnumerable<Exemption> exemptions, Func<ICustomAttributeProvider, string, string, IEnumerable<Exemption>, IEnumerable<string>> coreChecker) {
var types = module.GetTypes().Where(type => !IsGeneratedCode(type));
return Enumerable.Concat(
coreChecker(module, module.Name, "module", exemptions),
types.SelectMany(type => CollectErrorsOnMemberAndDescendents(type, exemptions, coreChecker)));
}
示例2: HandleModule
private static IEnumerable<ICommand> HandleModule(Module module)
{
IList<Type> types = module.GetTypes()
.Where(t => t.IsPublic &&
!t.IsAbstract).ToList();
return types.Select(Activator.CreateInstance).OfType<ICommand>();
}
示例3: AnalyzeModule
/// <summary>
/// 分析模块
/// </summary>
public static void AnalyzeModule(Module module)
{
Console.WriteLine("模块名:" + module.Name);
Console.WriteLine("模块的UUID:" + module.ModuleVersionId);
Console.WriteLine("开始分析模块下的类型");
Type[] types = module.GetTypes();
foreach (Type type in types)
{
AnalyzeType(type);
}
}
示例4: 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);
}
}
示例5: Add
public void Add(Module module)
{
ContractUtils.Requires(module != null);
Type[] types;
try {
types = module.GetTypes();
} catch (Exception) {
Console.WriteLine(module.Assembly.Location);
return;
}
foreach (Type type in types) {
if (type.Attributes.IsNested()) {
continue;
}
string prefix = type.Namespace ?? "";
RNamespaceTreeNode ns = null;
while (true) {
RNamespaceTreeNode existing;
if (_names.TryGetValue(prefix, out existing)) {
if (ns == null) {
existing.AddType(type);
} else {
existing.AddNamespace(ns);
}
break;
}
ContractUtils.Assert(prefix.Length > 0);
int lastDot = prefix.LastIndexOf('.', prefix.Length - 1, prefix.Length);
string name = (lastDot >= 0) ? prefix.Substring(lastDot + 1) : prefix;
RNamespaceTreeNode newNs = new RNamespaceTreeNode(name);
if (ns == null) {
newNs.AddType(type);
} else {
newNs.AddNamespace(ns);
}
ns = newNs;
_names.Add(prefix, ns);
prefix = (lastDot >= 0) ? prefix.Substring(0, lastDot) : "";
}
}
}
示例6: LoadModule
private void LoadModule(TreeNode parent, Module md)
{
ModuleTreeNode tn = new ModuleTreeNode(md);
parent.Nodes.Add(tn);
foreach (Type t in md.GetTypes())
{
if (!tn.Namespaces.ContainsKey((t.Namespace == null ? "-" : t.Namespace)))
{
TreeNode tnd = new NamespaceTreeNode((t.Namespace == null ? "-" : t.Namespace));
tn.Nodes.Add(tnd);
tn.Namespaces.Add((t.Namespace == null ? "-" : t.Namespace), tnd);
}
LoadType(tn.Namespaces[(t.Namespace == null ? "-" : t.Namespace)], t);
}
}
示例7: AddModuleReference
public void AddModuleReference(Module m)
{
int top = modules != null ? modules.Length : 0;
Module [] n = new Module [top + 1];
if (modules != null)
modules.CopyTo (n, 0);
n [top] = m;
modules = n;
if (m == RootContext.ToplevelTypes.Builder)
return;
foreach (var t in m.GetTypes ())
RegisterNamespace (t.Namespace);
}
示例8: 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);
}
}
示例9: getTypes
public List<Type> getTypes(Module module)
{
return new List<Type>(module.GetTypes());
}
示例10: AddModuleReference
public void AddModuleReference (Module m)
{
int top = modules != null ? modules.Length : 0;
Module [] n = new Module [top + 1];
if (modules != null)
modules.CopyTo (n, 0);
n [top] = m;
modules = n;
if (m == CodeGen.Module.Builder)
return;
foreach (Type t in m.GetTypes ())
RegisterNamespace (t.Namespace);
}
示例11: GetTypesPortable
public static Type[] GetTypesPortable(Module module)
{
return module.GetTypes();
}
示例12: ImportModule
private void ImportModule(Module module)
{
var type = module.GetTypes();
foreach (var t in type)
{
if (!t.IsPublic)
{
continue;
}
var ns = GetNameSpace(t.Namespace);
if (typeof(void) == t)
{
continue;
}
ns.Append(ImportType(t));
}
}
示例13: 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)
//.........这里部分代码省略.........
示例14: Refresh
public static void Refresh (Module module)
{
foreach (Type type in module.GetTypes())
Refresh (type);
}
示例15: FindAllTypes
private void FindAllTypes(List<Type> newlyFoundObjects, Assembly assembly, Module module)
{
Type[] types;
try
{
types = module.GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
//Since its possible that during enumeration, the GetTypes method can error, this will allow us
//to enumerate the types that did not error.
Log.Publish(MessageLevel.Error, "Reflection Load Error Occurred", assembly.GetName().Name, ex.ToString() + Environment.NewLine + String.Join(Environment.NewLine, ex.LoaderExceptions.Select(x => x.ToString())), ex);
types = ex.Types;
}
foreach (Type assemblyType in types)
{
try
{
if ((object)assemblyType != null)
{
newlyFoundObjects.Add(assemblyType);
}
}
catch (Exception ex)
{
Log.Publish(MessageLevel.Critical, MessageFlags.BugReport, "Static Constructor Error", null, null, ex);
}
}
}