/// <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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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 = ReflectionHelper.SplitTypeParameterCountFromReflectionName(parts[i + 1], out tpc);
                    nestedTypes[i] = new NestedTypeName(name, tpc);
                }
            }
        }
Beispiel #5
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;
 }
Beispiel #6
0
 private FullTypeName(TopLevelTypeName topLevelTypeName, NestedTypeName[] nestedTypes)
 {
     this.topLevelType = topLevelTypeName;
     this.nestedTypes  = nestedTypes;
 }