Пример #1
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 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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #4
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;
 }
Пример #5
0
 FullTypeName(TopLevelTypeName topLevelTypeName, NestedTypeName[] nestedTypes)
 {
     this.topLevelType = topLevelTypeName;
     this.nestedTypes  = nestedTypes;
 }