/// <summary> /// Creates a type reference anchored in the given assembly reference and whose names are relative to the given host. /// When the type name has periods in it, a structured reference with nested namespaces is created. /// </summary> protected static INamespaceTypeReference CreateTypeReference(IMetadataHost host, IAssemblyReference assemblyReference, string typeName) { Contract.Requires(host != null); Contract.Requires(assemblyReference != null); Contract.Requires(assemblyReference != Dummy.AssemblyReference); Contract.Requires(typeName != null); Contract.Requires(typeName != string.Empty); Contract.Ensures(Contract.Result <INamespaceTypeReference>() != null); Contract.Ensures(Contract.Result <INamespaceTypeReference>() != Dummy.NamespaceTypeReference); IUnitNamespaceReference ns = new Microsoft.Cci.Immutable.RootUnitNamespaceReference(assemblyReference); string[] names = typeName.Split('.'); for (int i = 0, n = names.Length - 1; i < n; i++) { ns = new Microsoft.Cci.Immutable.NestedUnitNamespaceReference(ns, host.NameTable.GetNameFor(names[i])); } return(new Microsoft.Cci.Immutable.NamespaceTypeReference(host, ns, host.NameTable.GetNameFor(names[names.Length - 1]), 0, false, false, PrimitiveTypeCode.NotPrimitive)); }
/// <summary> /// Creates a type reference anchored in the given assembly reference and whose names are relative to the given host. /// When the type name has periods in it, a structured reference with nested namespaces is created. /// </summary> protected static INamespaceTypeReference CreateTypeReference(IMetadataHost host, IAssemblyReference assemblyReference, string typeName) { Contract.Requires(host != null); Contract.Requires(assemblyReference != null); Contract.Requires(assemblyReference != Dummy.AssemblyReference); Contract.Requires(typeName != null); Contract.Requires(typeName != string.Empty); Contract.Ensures(Contract.Result<INamespaceTypeReference>() != null); Contract.Ensures(Contract.Result<INamespaceTypeReference>() != Dummy.NamespaceTypeReference); IUnitNamespaceReference ns = new Microsoft.Cci.Immutable.RootUnitNamespaceReference(assemblyReference); string[] names = typeName.Split('.'); for (int i = 0, n = names.Length - 1; i < n; i++) ns = new Microsoft.Cci.Immutable.NestedUnitNamespaceReference(ns, host.NameTable.GetNameFor(names[i])); return new Microsoft.Cci.Immutable.NamespaceTypeReference(host, ns, host.NameTable.GetNameFor(names[names.Length - 1]), 0, false, false, true, PrimitiveTypeCode.NotPrimitive); }
/// <summary> /// Creates a type reference to a namespace type from the given assembly, where the last element of the names /// array is the name of the type and the other elements are the names of the namespaces. /// </summary> /// <param name="assemblyReference">A reference to the assembly that contains the type for which a reference is desired.</param> /// <param name="isValueType">True if the referenced type is known to be a value type.</param> /// <param name="genericParameterCount">The number of generic parameters, if any, that the type has must. Must be zero or more.</param> /// <param name="typeCode">A code that identifies what kind of type is being referenced.</param> /// <param name="names">The last entry of this array is the name of the type, the others are the names of the containing namespaces.</param> public INamespaceTypeReference CreateReference(IAssemblyReference assemblyReference, bool isValueType, ushort genericParameterCount, PrimitiveTypeCode typeCode, params string[] names) { IUnitNamespaceReference ns = new RootUnitNamespaceReference(assemblyReference); for (int i = 0, n = names.Length-1; i < n; i++) ns = new NestedUnitNamespaceReference(ns, this.host.NameTable.GetNameFor(names[i])); return new NamespaceTypeReference(this.host, ns, this.host.NameTable.GetNameFor(names[names.Length-1]), genericParameterCount, false, isValueType, typeCode); }