コード例 #1
0
		/// <summary>
		/// Loads the assembly definition into a project content.
		/// </summary>
		/// <returns>IProjectContent that represents the assembly</returns>
		public IProjectContent LoadAssembly(AssemblyDefinition assemblyDefinition)
		{
			if (assemblyDefinition == null)
				throw new ArgumentNullException("assemblyDefinition");
			ITypeResolveContext oldEarlyBindContext = this.EarlyBindContext;
			try {
				IList<IAttribute> assemblyAttributes = new List<IAttribute>();
				foreach (var attr in assemblyDefinition.CustomAttributes) {
					assemblyAttributes.Add(ReadAttribute(attr));
				}
				if (this.InterningProvider != null)
					assemblyAttributes = this.InterningProvider.InternList(assemblyAttributes);
				else
					assemblyAttributes = new ReadOnlyCollection<IAttribute>(assemblyAttributes);
				TypeStorage typeStorage = new TypeStorage();
				CecilProjectContent pc = new CecilProjectContent(typeStorage, assemblyDefinition.Name.FullName, assemblyAttributes, this.DocumentationProvider);
				
				this.EarlyBindContext = CompositeTypeResolveContext.Combine(pc, this.EarlyBindContext);
				List<CecilTypeDefinition> types = new List<CecilTypeDefinition>();
				foreach (ModuleDefinition module in assemblyDefinition.Modules) {
					foreach (TypeDefinition td in module.Types) {
						if (this.IncludeInternalMembers || (td.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public) {
							string name = td.FullName;
							if (name.Length == 0 || name[0] == '<')
								continue;
							if (name == "System.Void") {
								var c = new VoidTypeDefinition(pc);
								AddAttributes(td, c);
								typeStorage.UpdateType(c);
							} else {
								CecilTypeDefinition c = new CecilTypeDefinition(pc, td);
								types.Add(c);
								typeStorage.UpdateType(c);
							}
						}
					}
				}
				foreach (CecilTypeDefinition c in types) {
					c.Init(this);
				}
				return pc;
			} finally {
				this.EarlyBindContext = oldEarlyBindContext;
			}
		}
コード例 #2
0
			public CecilTypeDefinition(CecilTypeDefinition parentType, string name, TypeDefinition typeDefinition)
				: base(parentType, name)
			{
				this.typeDefinition = typeDefinition;
				InitTypeParameters();
			}
コード例 #3
0
		/// <summary>
		/// Loads a type from Cecil.
		/// </summary>
		/// <param name="typeDefinition">The Cecil TypeDefinition.</param>
		/// <param name="projectContent">The project content used as parent for the new type.</param>
		/// <returns>ITypeDefinition representing the Cecil type.</returns>
		public ITypeDefinition LoadType(TypeDefinition typeDefinition, IProjectContent projectContent)
		{
			if (typeDefinition == null)
				throw new ArgumentNullException("typeDefinition");
			if (projectContent == null)
				throw new ArgumentNullException("projectContent");
			var c = new CecilTypeDefinition(projectContent, typeDefinition);
			c.Init(this);
			return c;
		}