public TypeReference ImportType(TypeReference type, IGenericContext context) { if (Mixin.IsTypeSpecification(type)) { return(ImportTypeSpecification(type, context)); } var reference = new TypeReference( type.Namespace, type.Name, module, ImportScope(type.Scope), type.IsValueType); MetadataSystem.TryProcessPrimitiveTypeReference(reference); if (type.IsNested) { reference.DeclaringType = ImportType(type.DeclaringType, context); } if (type.HasGenericParameters) { ImportGenericParameters(reference, type); } return(reference); }
static bool AreSame(TypeReference a, TypeReference b) { if (ReferenceEquals(a, b)) { return(true); } if (a == null || b == null) { return(false); } if (a.etype != b.etype) { return(false); } if (a.IsGenericParameter) { return(AreSame((GenericParameter)a, (GenericParameter)b)); } if (Mixin.IsTypeSpecification(a)) { return(AreSame((TypeSpecification)a, (TypeSpecification)b)); } if (a.Name != b.Name || a.Namespace != b.Namespace) { return(false); } //TODO: check scope return(AreSame(a.DeclaringType, b.DeclaringType)); }
static void AppendType(TypeReference type, StringBuilder name, bool fq_name, bool top_level) { var declaring_type = type.DeclaringType; if (declaring_type != null) { AppendType(declaring_type, name, false, top_level); name.Append('+'); } var @namespace = type.Namespace; if (!string.IsNullOrEmpty(@namespace)) { name.Append(@namespace); name.Append('.'); } name.Append(type.GetElementType().Name); if (!fq_name) { return; } if (Mixin.IsTypeSpecification(type)) { AppendTypeSpecification((TypeSpecification)type, name); } if (RequiresFullyQualifiedName(type, top_level)) { name.Append(", "); name.Append(GetScopeFullName(type)); } }
static void AppendTypeSpecification(TypeSpecification type, StringBuilder name) { if (Mixin.IsTypeSpecification(type.ElementType)) { AppendTypeSpecification((TypeSpecification)type.ElementType, name); } switch (type.etype) { case ElementType.Ptr: name.Append('*'); break; case ElementType.ByRef: name.Append('&'); break; case ElementType.SzArray: case ElementType.Array: var array = (ArrayType)type; if (array.IsVector) { name.Append("[]"); } else { name.Append('['); for (int i = 1; i < array.Rank; i++) { name.Append(','); } name.Append(']'); } break; case ElementType.GenericInst: var instance = (GenericInstanceType)type; var arguments = instance.GenericArguments; name.Append('['); for (int i = 0; i < arguments.Count; i++) { if (i > 0) { name.Append(','); } var argument = arguments[i]; var requires_fqname = argument.Scope != argument.Module; if (requires_fqname) { name.Append('['); } AppendType(argument, name, true, false); if (requires_fqname) { name.Append(']'); } } name.Append(']'); break; default: return; } }