GetTypes() public method

public GetTypes ( ) : Type[]
return Type[]
        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)));
        }
Example #2
0
        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>();
        }
Example #3
0
 private void PrintModule(System.Reflection.Module module)
 {
     Console.WriteLine();
     Console.WriteLine("Name: " + module.FullyQualifiedName);
     Console.WriteLine("Types:");
     foreach (var type in module.GetTypes())
     {
         Console.Write(" " + type.FullName);
     }
     Console.WriteLine();
 }
 /// <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);
     }
 }
Example #5
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);
     }
 }
Example #6
0
 public static IEnumerable <Type> FindConcreteImplementationsWithin(this Type type, System.Reflection.Module module)
 {
     // Must be an interface.
     if (type.IsInterface)
     {
         return
             (from t in module.GetTypes()
              where !t.IsAbstract
              from i in t.GetInterfaces()
              where i.Name == type.Name
              select t);
     }
     return(Enumerable.Empty <Type>());
 }
        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) : "";
                }
            }
        }
Example #8
0
 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);
     }
 }
Example #9
0
        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);
        }
Example #10
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);
				}
			}
Example #11
0
 public List<Type> getTypes(Module module)
 {
     return new List<Type>(module.GetTypes());
 }
Example #12
0
		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);
		}
Example #13
0
 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));
     }
 }
 public static Type[] GetTypesPortable(Module module)
 {
     return module.GetTypes();
 }
        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);
                }
            }
        }   
Example #16
0
		public ImportedModuleDefinition ImportModule (Module module, RootNamespace targetNamespace)
		{
			var module_definition = new ImportedModuleDefinition (module, this);
			module_definition.ReadAttributes ();

			Type[] all_types;
			try {
				all_types = module.GetTypes ();
			} catch (ReflectionTypeLoadException e) {
				all_types = e.Types;
			}

			ImportTypes (all_types, targetNamespace, false);

			return module_definition;
		}
Example #17
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);
        }
	public static void Refresh (Module module)
	{
		foreach (Type type in module.GetTypes())
			Refresh (type);
	}
Example #19
0
		public ImportedModuleDefinition ImportModule (Module module, RootNamespace targetNamespace)
		{
			var module_definition = new ImportedModuleDefinition (module, this);
			module_definition.ReadAttributes ();

			Type extension_type = HasExtensionAttribute (CustomAttributeData.GetCustomAttributes (module));

			Type[] all_types;
			try {
				all_types = module.GetTypes ();
			} catch (ReflectionTypeLoadException e) {
				all_types = e.Types;
			}

			ImportTypes (all_types, targetNamespace, extension_type);

			return module_definition;
		}
Example #20
0
		private void WriteNamespaces(XmlWriter writer, Module module)
		{
			Type[] types = module.GetTypes();

			StringCollection namespaceNames = GetNamespaceNames(types);

			foreach (string namespaceName in namespaceNames)
			{
				string ourNamespaceName;

				if (namespaceName == null)
				{
					ourNamespaceName = "(global)";
				}
				else
				{
					ourNamespaceName = namespaceName;
				}

				if (notEmptyNamespaces.ContainsKey(ourNamespaceName) || this.rep.DocumentEmptyNamespaces)
				{

					string namespaceSummary = null;
					if (this.rep.UseNamespaceDocSummaries)
					{
						if (namespaceName == null)
							namespaceSummary = assemblyDocCache.GetDoc("T:NamespaceDoc");
						else
							namespaceSummary = assemblyDocCache.GetDoc("T:" + namespaceName + ".NamespaceDoc");
					}

					bool isNamespaceDoc = false;

					if ((namespaceSummary == null) || (namespaceSummary.Length == 0))
						namespaceSummary = this.rep.NamespaceSummaries[ourNamespaceName] as string;
					else
						isNamespaceDoc = true;

					if (this.rep.SkipNamespacesWithoutSummaries && 
						(namespaceSummary == null || namespaceSummary.Length == 0))
					{
						Trace.WriteLine(string.Format("Skipping namespace {0} because it has no summary...", namespaceName));
					}
					else
					{
						Trace.WriteLine(string.Format("Writing namespace {0}...", namespaceName));

						writer.WriteStartElement("namespace");
						writer.WriteAttributeString("name", ourNamespaceName);

						if (namespaceSummary != null && namespaceSummary.Length > 0)
						{
							WriteStartDocumentation(writer);

							if (isNamespaceDoc)
							{
								writer.WriteRaw(namespaceSummary);
							}
							else
							{
								writer.WriteStartElement("summary");
								writer.WriteRaw(namespaceSummary);
								writer.WriteEndElement();
							}
							WriteEndDocumentation(writer);
						}
						else if (this.rep.ShowMissingSummaries)
						{
							WriteStartDocumentation(writer);
							WriteMissingDocumentation(writer, "summary", null, "Missing <summary> Documentation for " + namespaceName);
							WriteEndDocumentation(writer);
						}

						int classCount = WriteClasses(writer, types, namespaceName);
						Trace.WriteLine(string.Format("Wrote {0} classes.", classCount));

						int interfaceCount = WriteInterfaces(writer, types, namespaceName);
						Trace.WriteLine(string.Format("Wrote {0} interfaces.", interfaceCount));

						int structureCount = WriteStructures(writer, types, namespaceName);
						Trace.WriteLine(string.Format("Wrote {0} structures.", structureCount));

						int delegateCount = WriteDelegates(writer, types, namespaceName);
						Trace.WriteLine(string.Format("Wrote {0} delegates.", delegateCount));

						int enumCount = WriteEnumerations(writer, types, namespaceName);
						Trace.WriteLine(string.Format("Wrote {0} enumerations.", enumCount));

						writer.WriteEndElement();
					}
				}
				else
				{
					Trace.WriteLine(string.Format("Discarding namespace {0} because it does not contain any documented types.", ourNamespaceName));
				}
			}
		}
	public static void Refresh(Module module)
			{
				if(module != null)
				{
					foreach(Type type in module.GetTypes())
					{
						Refresh(null, type);
					}
				}
			}