Пример #1
0
        /// <summary>
        /// Creates a nested namespace (because only the root namespace is not nested
        /// and that is created when the assembly is created).
        /// Adds it to the namespace cache.
        /// </summary>
        /// <param name="namespaceSymbol"></param>
        /// <returns></returns>
        private NestedUnitNamespace CreateNamespaceDefinition(R.INamespaceSymbol namespaceSymbol)
        {
            var ns = new NestedUnitNamespace()
            {
                ContainingUnitNamespace = (IUnitNamespace)this.namespaceSymbolCache[namespaceSymbol.ContainingNamespace],
                Locations = Helper.WrapLocations(namespaceSymbol.Locations),
                Name      = this.host.NameTable.GetNameFor(namespaceSymbol.Name),
                //Unit = (IUnit)this.assemblySymbolCache[namespaceSymbol.ContainingAssembly],
            };

            this.namespaceSymbolCache.Add(namespaceSymbol, ns);
            return(ns);
        }
Пример #2
0
        private NestedUnitNamespace TranslateMetadata(R.INamespaceSymbol namespaceSymbol)
        {
            Contract.Requires(namespaceSymbol != null);
            Contract.Ensures(Contract.Result <UnitNamespace>() != null);

            IUnitNamespaceReference nsr;

            if (this.namespaceSymbolCache.TryGetValue(namespaceSymbol, out nsr))
            {
                var alreadyTranslatedNamespace = nsr as IUnitNamespace;
                if (alreadyTranslatedNamespace != null)
                {
                    return(alreadyTranslatedNamespace as NestedUnitNamespace);
                }
            }

            var ns = CreateNamespaceDefinition(namespaceSymbol);

            var mems = new List <INamespaceMember>();

            foreach (var m in namespaceSymbol.GetMembers())
            {
                var nestedNamespaceSymbol = m as R.INamespaceSymbol;
                if (nestedNamespaceSymbol != null)
                {
                    var cciNtd = TranslateMetadata(nestedNamespaceSymbol);
                    mems.Add(cciNtd);
                }

                var typeSymbol = m as R.INamedTypeSymbol;
                if (typeSymbol != null)
                {
                    var cciType = (INamespaceTypeDefinition)TranslateMetadata(typeSymbol);
                    mems.Add(cciType);
                    continue;
                }
            }
            ns.Members = mems;
            return(ns);
        }
Пример #3
0
        public IUnitNamespaceReference Map(R.INamespaceSymbol namespaceSymbol)
        {
            Contract.Requires(namespaceSymbol != null);
            Contract.Ensures(Contract.Result <IUnitNamespaceReference>() != null);
            IUnitNamespaceReference nsr = null;

            if (!namespaceSymbolCache.TryGetValue(namespaceSymbol, out nsr))
            {
                if (namespaceSymbol.ContainingAssembly.Equals(this.assemblyBeingTranslated))
                {
                    var n = this.CreateNamespaceDefinition(namespaceSymbol);
                    return(n);
                }

                if (namespaceSymbol.IsGlobalNamespace)
                {
                    var n = new Microsoft.Cci.MutableCodeModel.RootUnitNamespaceReference()
                    {
                        Unit = Map(namespaceSymbol.ContainingAssembly),
                    };
                    nsr = n;
                }
                else
                {
                    var ns = new Microsoft.Cci.MutableCodeModel.NestedUnitNamespaceReference()
                    {
                        ContainingUnitNamespace = Map(namespaceSymbol.ContainingNamespace),
                        Name = this.nameTable.GetNameFor(namespaceSymbol.Name),
                    };
                    nsr = ns;
                }
                namespaceSymbolCache[namespaceSymbol] = nsr;
            }
            Contract.Assume(nsr != null);
            return(nsr);
        }