Beispiel #1
0
        public IUnitNamespaceReference Map(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);
        }
    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;
    }