コード例 #1
0
        /// <summary>
        /// Adds the type definition to this project content.
        /// Replaces existing type definitions with the same name.
        /// </summary>
        public void UpdateType(ITypeDefinition typeDefinition)
        {
            if (typeDefinition == null)
            {
                throw new ArgumentNullException("typeDefinition");
            }
            var  key   = new FullNameAndTypeParameterCount(typeDefinition.Namespace, typeDefinition.Name, typeDefinition.TypeParameterCount);
            bool isNew = !_typeDicts[0].ContainsKey(key);

            foreach (var dict in _typeDicts)
            {
                dict[key] = typeDefinition;
            }
            if (isNew)
            {
                foreach (var dict in _namespaceDicts)
                {
                    NamespaceEntry ns;
                    if (dict.TryGetValue(typeDefinition.Namespace, out ns))
                    {
                        ++ns.ClassCount;
                    }
                    else
                    {
                        dict.Add(typeDefinition.Namespace, new NamespaceEntry(typeDefinition.Namespace)
                        {
                            ClassCount = 1
                        });
                    }
                }
            }
        }
コード例 #2
0
        /// <inheritdoc/>
        public ITypeDefinition GetClass(string nameSpace, string name, int typeParameterCount, StringComparer nameComparer)
        {
            if (nameSpace == null)
            {
                throw new ArgumentNullException("nameSpace");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (nameComparer == null)
            {
                throw new ArgumentNullException("nameComparer");
            }

            var             key = new FullNameAndTypeParameterCount(nameSpace, name, typeParameterCount);
            ITypeDefinition result;

            if (GetTypeDictionary(nameComparer).TryGetValue(key, out result))
            {
                return(result);
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        public IUnresolvedTypeDefinition GetTypeDefinition(string ns, string name, int typeParameterCount)
        {
            var key = new FullNameAndTypeParameterCount(ns ?? string.Empty, name, typeParameterCount);
            IUnresolvedTypeDefinition td;

            if (typeDefinitions.TryGetValue(key, out td))
            {
                return(td);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
                ITypeDefinition INamespace.GetTypeDefinition(string name, int typeParameterCount)
                {
                    var key = new FullNameAndTypeParameterCount(ns.FullName, name, typeParameterCount);
                    IUnresolvedTypeDefinition unresolvedTypeDef;

                    if (assembly.unresolvedTypeDict.TryGetValue(key, out unresolvedTypeDef))
                    {
                        return(assembly.GetTypeDefinition(unresolvedTypeDef));
                    }
                    else
                    {
                        return(null);
                    }
                }
コード例 #5
0
        /// <summary>
        /// Adds a type forwarder.
        /// This adds both an assembly attribute and an internal forwarder entry, which will be used
        /// by the resolved assembly to provide the forwarded types.
        /// </summary>
        /// <param name="typeName">The name of the type.</param>
        /// <param name="referencedType">The reference used to look up the type in the target assembly.</param>
        public void AddTypeForwarder(FullNameAndTypeParameterCount typeName, ITypeReference referencedType)
        {
            if (referencedType == null)
            {
                throw new ArgumentNullException("referencedType");
            }
            FreezableHelper.ThrowIfFrozen(this);
            var attribute = new DefaultUnresolvedAttribute(typeForwardedToAttributeTypeRef, new[] { KnownTypeReference.Type });

            attribute.PositionalArguments.Add(new TypeOfConstantValue(referencedType));
            assemblyAttributes.Add(attribute);

            typeForwarders[typeName] = referencedType;
        }
コード例 #6
0
        /// <summary>
        /// Adds a new top-level type definition to this assembly.
        /// </summary>
        /// <remarks>DefaultUnresolvedAssembly does not support partial classes.
        /// Adding more than one part of a type will cause an ArgumentException.</remarks>
        public void AddTypeDefinition(IUnresolvedTypeDefinition typeDefinition)
        {
            if (typeDefinition == null)
            {
                throw new ArgumentNullException("typeDefinition");
            }
            if (typeDefinition.DeclaringTypeDefinition != null)
            {
                throw new ArgumentException("Cannot add nested types.");
            }
            FreezableHelper.ThrowIfFrozen(this);
            var key = new FullNameAndTypeParameterCount(typeDefinition.Namespace, typeDefinition.Name, typeDefinition.TypeParameters.Count);

            typeDefinitions.Add(key, typeDefinition);
        }
コード例 #7
0
            public ITypeDefinition GetTypeDefinition(string ns, string name, int typeParameterCount)
            {
                var key = new FullNameAndTypeParameterCount(ns ?? string.Empty, name, typeParameterCount);

                IUnresolvedTypeDefinition td;
                ITypeReference            typeRef;

                if (unresolvedAssembly.typeDefinitions.TryGetValue(key, out td))
                {
                    return(GetTypeDefinition(td));
                }
                else if (unresolvedAssembly.typeForwarders.TryGetValue(key, out typeRef))
                {
                    return(typeRef.Resolve(compilation.TypeResolveContext).GetDefinition());
                }
                else
                {
                    return(null);
                }
            }
コード例 #8
0
ファイル: TypeStorage.cs プロジェクト: yayanyang/monodevelop
        /// <summary>
        /// Removes a type definition from this project content.
        /// </summary>
        public bool RemoveType(ITypeDefinition typeDefinition)
        {
            if (typeDefinition == null)
            {
                throw new ArgumentNullException("typeDefinition");
            }
            var  key        = new FullNameAndTypeParameterCount(typeDefinition.Namespace, typeDefinition.Name, typeDefinition.TypeParameterCount);
            bool wasRemoved = false;

            foreach (var dict in _typeDicts)
            {
                ITypeDefinition defInDict;
                if (dict.TryGetValue(key, out defInDict))
                {
                    if (defInDict == typeDefinition)
                    {
                        if (dict.Comparer == FullNameAndTypeParameterCountComparer.Ordinal)
                        {
                            // Set wasRemoved flag only on removal in the ordinal comparison.
                            // This keeps the ClassCount consistent when there are name clashes.
                            wasRemoved = true;
                        }
                        dict.Remove(key);
                    }
                }
            }
            if (wasRemoved)
            {
                foreach (var dict in _namespaceDicts)
                {
                    NamespaceEntry ns;
                    if (dict.TryGetValue(typeDefinition.Namespace, out ns))
                    {
                        ns.ClassCount--;
                        RemoveNamespaceIfPossible(dict, ns);
                    }
                }
            }
            return(wasRemoved);
        }
コード例 #9
0
        /// <summary>
        /// Removes a type definition from this project content.
        /// </summary>
        public void RemoveType(ITypeDefinition typeDefinition)
        {
            if (typeDefinition == null)
            {
                throw new ArgumentNullException("typeDefinition");
            }
            var  key        = new FullNameAndTypeParameterCount(typeDefinition.Namespace, typeDefinition.Name, typeDefinition.TypeParameterCount);
            bool wasRemoved = false;

            foreach (var dict in _typeDicts)
            {
                ITypeDefinition defInDict;
                if (dict.TryGetValue(key, out defInDict))
                {
                    if (defInDict == typeDefinition)
                    {
                        wasRemoved = true;
                        dict.Remove(key);
                    }
                }
            }
            if (wasRemoved)
            {
                foreach (var dict in _namespaceDicts)
                {
                    NamespaceEntry ns;
                    if (dict.TryGetValue(typeDefinition.Namespace, out ns))
                    {
                        if (--ns.ClassCount == 0)
                        {
                            dict.Remove(typeDefinition.Namespace);
                        }
                    }
                }
            }
        }
コード例 #10
0
ファイル: TypeStorage.cs プロジェクト: yayanyang/monodevelop
        /// <summary>
        /// Adds the type definition to this project content.
        /// Replaces existing type definitions with the same name.
        /// </summary>
        public void UpdateType(ITypeDefinition typeDefinition)
        {
            if (typeDefinition == null)
            {
                throw new ArgumentNullException("typeDefinition");
            }
            var key = new FullNameAndTypeParameterCount(typeDefinition.Namespace, typeDefinition.Name, typeDefinition.TypeParameterCount);
            // Set isNew on addition in the ordinal comparison.
            // This keeps the ClassCount consistent when there are name clashes.
            bool isNew = !_typeDicts[0].ContainsKey(key);

            foreach (var dict in _typeDicts)
            {
                dict[key] = typeDefinition;
            }
            if (isNew)
            {
                foreach (var dict in _namespaceDicts)
                {
                    NamespaceEntry ns = GetOrCreateNamespaceEntry(dict, typeDefinition.Namespace);
                    ++ns.ClassCount;
                }
            }
        }