/// <summary>
        /// Gets the type definition for the specified unresolved type.
        /// Returns null if the unresolved type does not belong to this assembly.
        /// </summary>
        public static ITypeDefinition GetTypeDefinition(this IAssembly assembly, FullTypeName fullTypeName)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }
            TopLevelTypeName topLevelTypeName = fullTypeName.TopLevelTypeName;
            ITypeDefinition  typeDef          = assembly.GetTypeDefinition(topLevelTypeName);

            if (typeDef == null)
            {
                return(null);
            }
            int typeParameterCount = topLevelTypeName.TypeParameterCount;

            for (int i = 0; i < fullTypeName.NestingLevel; i++)
            {
                string name = fullTypeName.GetNestedTypeName(i);
                typeParameterCount += fullTypeName.GetNestedTypeAdditionalTypeParameterCount(i);
                typeDef             = FindNestedType(typeDef, name, typeParameterCount);
                if (typeDef == null)
                {
                    break;
                }
            }
            return(typeDef);
        }
Esempio n. 2
0
		/// <summary>
		/// Gets the type definition for the specified unresolved type.
		/// Returns null if the unresolved type does not belong to this assembly.
		/// </summary>
		public static ITypeDefinition GetTypeDefinition(this IModule module, FullTypeName fullTypeName)
		{
			if (module == null)
				throw new ArgumentNullException("assembly");
			TopLevelTypeName topLevelTypeName = fullTypeName.TopLevelTypeName;
			ITypeDefinition typeDef = module.GetTypeDefinition(topLevelTypeName);
			if (typeDef == null)
				return null;
			int typeParameterCount = topLevelTypeName.TypeParameterCount;
			for (int i = 0; i < fullTypeName.NestingLevel; i++) {
				string name = fullTypeName.GetNestedTypeName(i);
				typeParameterCount += fullTypeName.GetNestedTypeAdditionalTypeParameterCount(i);
				typeDef = FindNestedType(typeDef, name, typeParameterCount);
				if (typeDef == null)
					break;
			}
			return typeDef;
		}