Ejemplo n.º 1
0
        /// <summary>
        /// Gets the namespace of the given key provided the <paramref name="path"/>
        /// to the namespace.
        /// </summary>
        /// <param name="target">The <see cref="INamespaceDictionary"/> which
        /// contain the namespace hierarchy.</param>
        /// <param name="path">The <see cref="String"/> representing the relative path to follow
        /// to obtain the namespace declaration.</param>
        /// <returns>A new <see cref="INamespaceDeclaration"/> relative to the <paramref name="path"/>
        /// provided.</returns>
        public static INamespaceDeclaration GetThis(this INamespaceDictionary target, string path)
        {
            var pathVariants = path.NamespacePathBreakdown();

            if (target.Parent is INamespaceDeclaration)
            {
                pathVariants = pathVariants.Except(((INamespaceDeclaration)(target.Parent)).FullName.NamespacePathBreakdown()).ToArray();
            }
            INamespaceDictionary currentDictionary = target;

            foreach (var currentPath in pathVariants)
            {
                if (currentDictionary.ContainsKey(currentPath))
                {
                    currentDictionary = currentDictionary.Values[currentDictionary.Keys.IndexOf(currentPath)].Namespaces;
                }
                else
                {
                    currentDictionary = null;
                    break;
                }
            }
            if (currentDictionary != null)
            {
                return(currentDictionary.Parent as INamespaceDeclaration);
            }
            throw new ArgumentOutOfRangeException("path");
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Disposes the resources and references associated to the
 /// <see cref="AssemblyBase"/>.
 /// </summary>
 /// <param name="disposing">Whether to release the managed resources
 /// as well as the unmanaged resources.</param>
 protected virtual void Dispose(bool disposing)
 {
     try
     {
         lock (this.SyncObject)
         {
             this.manifestModule = null;
             if (this.attributes != null)
             {
                 this.attributes.Dispose();
             }
             if (this.namespaces != null)
             {
                 this.namespaces.Dispose();
                 this.namespaces = null;
             }
             if (this.classes != null)
             {
                 this.classes.Dispose();
                 this.classes = null;
             }
             if (this.enums != null)
             {
                 this.enums.Dispose();
                 this.enums = null;
             }
             if (this.delegates != null)
             {
                 this.delegates.Dispose();
                 this.delegates = null;
             }
             if (this.interfaces != null)
             {
                 this.interfaces.Dispose();
                 this.interfaces = null;
             }
             if (this.structs != null)
             {
                 this.structs.Dispose();
                 this.structs = null;
             }
             if (this.modules != null)
             {
                 foreach (var module in this.modules.Values)
                 {
                     module.Dispose();
                 }
                 this.modules = null;
             }
             this.types      = null;
             this.isDisposed = 1;
         }
     }
     finally
     {
         this.OnDisposed();
         this.Disposed = null;
         GC.SuppressFinalize(this);
     }
 }
Ejemplo n.º 3
0
        public INamespaceDeclaration this[string path]
        {
            get
            {
                string ns = path;

                int lastIndex = 0;
                CliNamespaceKeyedTree topLevel         = this.info;
                INamespaceDictionary  topNamespaceDict = this;
                StringBuilder         pathBuilder      = new StringBuilder();
                bool first = true;
nextPart:
                int next = ns.IndexOf('.', lastIndex);
                if (first)
                {
                    first = false;
                }
                else
                {
                    pathBuilder.Append('.');
                }
                if (next != -1)
                {
                    string current = ns.Substring(lastIndex, next - lastIndex);
                    pathBuilder.Append(current);
                    uint currentHash = (uint)current.GetHashCode();
                    if (topLevel.ContainsKey(currentHash))
                    {
                        topLevel         = topLevel[currentHash];
                        topNamespaceDict = topNamespaceDict[TypeSystemIdentifiers.GetDeclarationIdentifier(pathBuilder.ToString())].Namespaces;
                    }
                    else
                    {
                        return(null);
                    }
                    lastIndex = next + 1;
                    goto nextPart;
                }
                else
                {
                    string current = ns.Substring(lastIndex);
                    pathBuilder.Append(current);
                    uint currentHash = (uint)current.GetHashCode();
                    if (topLevel.ContainsKey(currentHash))
                    {
                        topLevel = topLevel[currentHash];
                        return(topNamespaceDict[TypeSystemIdentifiers.GetDeclarationIdentifier(pathBuilder.ToString())]);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }