Ejemplo n.º 1
0
        public TypeKey(TypeReference type)
        {
            this.scope = Helper.GetScopeName(type);

            this.name = type.Name;
            TypeReference declaringType = type;

            // Build path to nested type
            while (declaringType.DeclaringType != null)
            {
                declaringType = declaringType.DeclaringType;
                this.name     = declaringType.Name + "/" + name;
            }
            this.ns = declaringType.Namespace;

            this.fullname = !string.IsNullOrEmpty(this.ns) ? this.ns + "." + name : name;

            // Our name should be the same as the Cecil's name. This is important to the Match method.
            GenericInstanceType gi = type as GenericInstanceType;

            if (this.fullname != type.ToString() && (gi == null || this.fullname != gi.ElementType.FullName))
            {
                throw new InvalidOperationException(string.Format("Type names do not match: \"{0}\" != \"{1}\"", this.fullname, type.ToString( )));
            }

            this.hashCode = CalcHashCode( );
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Recursively builds a type name.
        /// </summary>
        /// <param name="builder">Builder the type name will be added to.</param>
        /// <param name="type">Type whose name is to be built.</param>
        static void BuildTypeName(StringBuilder builder, TypeReference type)
        {
            GenericParameter genParam = type as GenericParameter;

            if (genParam != null)
            {
                builder.AppendFormat("!{0}", genParam.Position);
            }
            else
            {
                GenericInstanceType genType = type as GenericInstanceType;
                if (genType != null)
                {
                    builder.AppendFormat("[{2}]{0}.{1}<", genType.Namespace, genType.Name, Helper.GetScopeName(type));
                    for (int i = 0; i < genType.GenericArguments.Count; i++)
                    {
                        TypeReference argType = genType.GenericArguments[i];

                        if (i > 0)
                        {
                            builder.Append(',');
                        }

                        BuildTypeName(builder, argType);
                    }
                    builder.Append(">");
                }
                else
                {
                    ArrayType arrType = type as ArrayType;
                    if (arrType != null)
                    {
                        BuildTypeName(builder, arrType.ElementType);
                        builder.Append("[]");
                    }
                    else
                    {
                        builder.Append(String.Format("[{1}]{0}", type.FullName, Helper.GetScopeName(type)));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public TypeDefinition GetTypeDefinition(TypeReference type)
        {
            if (type == null)
            {
                return(null);
            }

            TypeDefinition typeDef = type as TypeDefinition;

            if (typeDef == null)
            {
                string name = Helper.GetScopeName(type);

                AssemblyInfo info;
                if (assemblyMap.TryGetValue(name, out info))
                {
                    string fullName = type.Namespace + "." + type.Name;
                    typeDef = info.Definition.MainModule.GetType(fullName);
                }
            }

            return(typeDef);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns whether the project contains a given type.
        /// </summary>
        public bool Contains(TypeReference type)
        {
            string name = Helper.GetScopeName(type);

            return(assemblyMap.ContainsKey(name));
        }