Exemplo n.º 1
0
        public ITypeReference ToTypeReference()
        {
            ITypeDefinition declTypeDef = this.DeclaringTypeDefinition;

            if (declTypeDef != null)
            {
                return(new NestedTypeReference(declTypeDef.ToTypeReference(), this.Name, this.TypeParameterCount - declTypeDef.TypeParameterCount));
            }
            else
            {
                IAssembly          asm = this.ParentAssembly;
                IAssemblyReference asmRef;
                if (asm != null)
                {
                    asmRef = new DefaultAssemblyReference(asm.AssemblyName);
                }
                else
                {
                    asmRef = DefaultAssemblyReference.CurrentAssembly;
                }
                return(new GetClassTypeReference(asmRef, this.Namespace, this.Name, this.TypeParameterCount));
            }
        }
        bool ISupportsInterning.EqualsForInterning(ISupportsInterning other)
        {
            DefaultAssemblyReference o = other as DefaultAssemblyReference;

            return(o != null && shortName == o.shortName);
        }
Exemplo n.º 3
0
		static ITypeReference CreateGetClassTypeReference(string assemblyName, string typeName, int tpc)
		{
			IAssemblyReference assemblyReference;
			if (assemblyName != null) {
				assemblyReference = new DefaultAssemblyReference(assemblyName);
			} else {
				assemblyReference = null;
			}
			int pos = typeName.LastIndexOf('.');
			if (pos < 0)
				return new GetClassTypeReference(assemblyReference, string.Empty, typeName, tpc);
			else
				return new GetClassTypeReference(assemblyReference, typeName.Substring(0, pos), typeName.Substring(pos + 1), tpc);
		}
Exemplo n.º 4
0
		/// <summary>
		/// Creates a reference to the specified type.
		/// </summary>
		/// <param name="type">The type to be converted.</param>
		/// <returns>Returns the type reference.</returns>
		/// <remarks>
		/// If the type is open (contains type parameters '`0' or '``0'),
		/// an <see cref="ITypeResolveContext"/> with the appropriate CurrentTypeDefinition/CurrentMember is required
		/// to resolve the type reference.
		/// For closed types, the root type resolve context for the compilation is sufficient.
		/// </remarks>
		public static ITypeReference ToTypeReference(this Type type)
		{
			if (type == null)
				return SpecialType.UnknownType;
			if (type.IsGenericType && !type.IsGenericTypeDefinition) {
				ITypeReference def = ToTypeReference(type.GetGenericTypeDefinition());
				Type[] arguments = type.GetGenericArguments();
				ITypeReference[] args = new ITypeReference[arguments.Length];
				bool allUnbound = true;
				for (int i = 0; i < arguments.Length; i++) {
					args[i] = ToTypeReference(arguments[i]);
					allUnbound &= args[i].Equals(SpecialType.UnboundTypeArgument);
				}
				if (allUnbound)
					return def;
				else
					return new ParameterizedTypeReference(def, args);
			} else if (type.IsArray) {
				return new ArrayTypeReference(ToTypeReference(type.GetElementType()), type.GetArrayRank());
			} else if (type.IsPointer) {
				return new PointerTypeReference(ToTypeReference(type.GetElementType()));
			} else if (type.IsByRef) {
				return new ByReferenceTypeReference(ToTypeReference(type.GetElementType()));
			} else if (type.IsGenericParameter) {
				if (type.DeclaringMethod != null) {
					return TypeParameterReference.Create(SymbolKind.Method, type.GenericParameterPosition);
				} else {
					return TypeParameterReference.Create(SymbolKind.TypeDefinition, type.GenericParameterPosition);
				}
			} else if (type.DeclaringType != null) {
				if (type == typeof(Dynamic))
					return SpecialType.Dynamic;
				else if (type == typeof(Null))
					return SpecialType.NullType;
				else if (type == typeof(UnboundTypeArgument))
					return SpecialType.UnboundTypeArgument;
				ITypeReference baseTypeRef = ToTypeReference(type.DeclaringType);
				int typeParameterCount;
				string name = SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount);
				return new NestedTypeReference(baseTypeRef, name, typeParameterCount);
			} else {
				IAssemblyReference assemblyReference = new DefaultAssemblyReference(type.Assembly.FullName);
				int typeParameterCount;
				string name = SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount);
				return new GetClassTypeReference(assemblyReference, type.Namespace, name, typeParameterCount);
			}
		}
Exemplo n.º 5
0
		public static ITypeReference CreateClrNamespaceTypeReference(string @namespace, string localName)
		{
			if (@namespace == null)
				return new UnknownType(null, localName);
			int assemblyNameIndex = @namespace.IndexOf(";assembly=", StringComparison.OrdinalIgnoreCase);
			IAssemblyReference asm = DefaultAssemblyReference.CurrentAssembly;
			if (assemblyNameIndex > -1) {
				asm = new DefaultAssemblyReference(@namespace.Substring(assemblyNameIndex + ";assembly=".Length));
				@namespace = @namespace.Substring(0, assemblyNameIndex);
			}
			return new GetClassTypeReference(asm, @namespace, localName, 0);
		}