Ejemplo n.º 1
0
        public bool Equals(FullTypeName x, FullTypeName y)
        {
            if (x.NestingLevel != y.NestingLevel)
            {
                return(false);
            }
            TopLevelTypeName topX = x.TopLevelTypeName;
            TopLevelTypeName topY = y.TopLevelTypeName;

            if (topX.TypeParameterCount == topY.TypeParameterCount &&
                NameComparer.Equals(topX.Name, topY.Name) &&
                NameComparer.Equals(topX.Namespace, topY.Namespace))
            {
                for (int i = 0; i < x.NestingLevel; i++)
                {
                    if (x.GetNestedTypeAdditionalTypeParameterCount(i) != y.GetNestedTypeAdditionalTypeParameterCount(i))
                    {
                        return(false);
                    }
                    if (!NameComparer.Equals(x.GetNestedTypeName(i), y.GetNestedTypeName(i)))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
        /// <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);
        }
Ejemplo n.º 3
0
        private static IType FindValueTupleType(ICompilation compilation, IModule valueTupleAssembly, int tpc)
        {
            var typeName = new TopLevelTypeName("System", "ValueTuple", tpc);

            if (valueTupleAssembly != null)
            {
                var typeDef = valueTupleAssembly.GetTypeDefinition(typeName);
                if (typeDef != null)
                {
                    return(typeDef);
                }
            }
            return(compilation.FindType(typeName));
        }
Ejemplo n.º 4
0
        public int GetHashCode(FullTypeName obj)
        {
            TopLevelTypeName top = obj.TopLevelTypeName;
            int hash             = NameComparer.GetHashCode(top.Name) ^ NameComparer.GetHashCode(top.Namespace) ^ top.TypeParameterCount;

            unchecked {
                for (int i = 0; i < obj.NestingLevel; i++)
                {
                    hash *= 31;
                    hash += NameComparer.GetHashCode(obj.Name) ^ obj.TypeParameterCount;
                }
            }
            return(hash);
        }
Ejemplo n.º 5
0
        public ITypeDefinition GetTypeDefinition(TopLevelTypeName topLevelTypeName)
        {
            var typeDefHandle = PEFile.GetTypeDefinition(topLevelTypeName);

            if (typeDefHandle.IsNil)
            {
                var forwarderHandle = PEFile.GetTypeForwarder(topLevelTypeName);
                if (!forwarderHandle.IsNil)
                {
                    var forwarder = metadata.GetExportedType(forwarderHandle);
                    return(ResolveForwardedType(forwarder).GetDefinition());
                }
            }
            return(GetDefinition(typeDefHandle));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Gets whether the specified type is a generic Task-like type.
 /// </summary>
 /// <param name="builderTypeName">Returns the full type-name of the builder type, if successful.</param>
 public static bool IsGenericTaskType(IType task, out FullTypeName builderTypeName)
 {
     if (task.IsKnownType(KnownTypeCode.TaskOfT))
     {
         builderTypeName = new TopLevelTypeName(ns, "AsyncTaskMethodBuilder", 1);
         return(true);
     }
     if (IsCustomTask(task, out var builderType))
     {
         builderTypeName = new FullTypeName(builderType.ReflectionName);
         return(builderTypeName.TypeParameterCount == 1);
     }
     builderTypeName = default;
     return(false);
 }
Ejemplo n.º 7
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;
		}
Ejemplo n.º 8
0
        /// <summary>
        /// Constructs a FullTypeName by parsing the given reflection name.
        /// Note that FullTypeName can only represent type definition names. If the reflection name
        /// might refer to a parameterized type or array etc., use
        /// <see cref="ReflectionHelper.ParseReflectionName(string)"/> instead.
        /// </summary>
        /// <remarks>
        /// Expected syntax: <c>NamespaceName '.' TopLevelTypeName ['`'#] { '+' NestedTypeName ['`'#] }</c>
        /// where # are type parameter counts
        /// </remarks>
        public FullTypeName(string reflectionName)
        {
            int pos = reflectionName.IndexOf('+');

            if (pos < 0)
            {
                // top-level type
                this.topLevelType = new TopLevelTypeName(reflectionName);
                this.nestedTypes  = null;
            }
            else
            {
                // nested type
                string[] parts = reflectionName.Split('+');
                this.topLevelType = new TopLevelTypeName(parts[0]);
                this.nestedTypes  = new NestedTypeName[parts.Length - 1];
                for (int i = 0; i < nestedTypes.Length; i++)
                {
                    int    tpc;
                    string name = SRMExtensions.SplitTypeParameterCountFromReflectionName(parts[i + 1], out tpc);
                    nestedTypes[i] = new NestedTypeName(name, tpc);
                }
            }
        }
Ejemplo n.º 9
0
 internal static bool IsKnownType(this TopLevelTypeName typeName, KnownAttribute knownType)
 {
     return(typeName == knownType.GetTypeName());
 }
Ejemplo n.º 10
0
 public static bool IsKnownType(this TopLevelTypeName typeName, KnownTypeCode knownType)
 {
     return(typeName == KnownTypeReference.Get(knownType).TypeName);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Constructs a FullTypeName representing the given top-level type.
 /// </summary>
 /// <remarks>
 /// FullTypeName has an implicit conversion operator from TopLevelTypeName,
 /// so you can simply write:
 /// <c>FullTypeName f = new TopLevelTypeName(...);</c>
 /// </remarks>
 public FullTypeName(TopLevelTypeName topLevelTypeName)
 {
     this.topLevelType = topLevelTypeName;
     this.nestedTypes  = null;
 }
Ejemplo n.º 12
0
 FullTypeName(TopLevelTypeName topLevelTypeName, NestedTypeName[] nestedTypes)
 {
     this.topLevelType = topLevelTypeName;
     this.nestedTypes  = nestedTypes;
 }