/// <summary> /// Gets the <see cref="TypeDefinitionData"/> instance representing the specified type. /// </summary> /// <typeparam name="T">The type for which to get the <see cref="TypeDefinitionData"/>.</typeparam> /// <returns>The <see cref="TypeDefinitionData"/> instance.</returns> public new static TypeDefinitionData FromType <T>() { return(TypeDefinitionData.FromType(typeof(T))); }
/// <summary> /// Gets the <see cref="TypeData"/> instance containing the metadata for externally visible types and members of the specified <see cref="Type"/>. /// </summary> /// <param name="type">The type for which of corresponding to the TypeData to get.</param> /// <returns>The TypeData instance containing the metadata for externally visible types and members of the specified Type.</returns> #endif internal TypeData GetTypeData(TypeReference type) { Debug.Assert(type.GetType() != typeof(TypeReference), "The type has not been resolved yet, and may be from a different assembly."); Debug.Assert(type.GetDeclaringAssembly().FullName == this.FullName, "The type belongs to another assembly."); var genericParameter = type as GenericParameter; if (genericParameter != null) { return(this.GetGenericTypeParameterData(genericParameter)); } var accessibility = type.GetAccessibility(); if (accessibility == null) { return(null); } var typeDefinition = type as TypeDefinition; if (typeDefinition != null) { return(this.GetTypeDefinitionData(typeDefinition.FullName)); } DeclaringTypeData declaringType = null; if (type.DeclaringType != null) { declaringType = (DeclaringTypeData)this.GetTypeData(type.DeclaringType.Resolve()); } var genericInstance = type as GenericInstanceType; if (genericInstance != null) { return(TypeDefinitionData.FromType(genericInstance.ElementType).GetConstructedGenericTypeData(genericInstance.GenericArguments.Select(a => TypeData.FromType(a)))); } if (type.IsByReference) { Debug.Fail("We should never create representations for by-ref types. They can only be parameter types and ref or out parameters store the element type and indicate whether they are ref or out."); return(null); } var arrayType = type as ArrayType; if (arrayType != null) { Debug.Assert(declaringType == null, "Types with elements should not be declared within other types."); return(TypeData.FromType(arrayType.ElementType).GetArrayType((byte)arrayType.Rank)); } var pointerType = type as PointerType; if (pointerType != null) { return(TypeData.FromType(pointerType.ElementType).GetPointerType()); } var modifierType = type as IModifierType; if (modifierType != null) { return(TypeData.FromType(modifierType.ElementType)); } Debug.Fail("Unknown kind of type."); return(TypeData.FromType(type.Resolve())); }