public int GetCountFor(IIntermediateNamespaceParent parent)
        {
            int result = 0;

            foreach (var element in this.Values)
            {
                if (element.Parent == parent)
                {
                    result++;
                }
                else
                {
                    foreach (var part in element.Parts)
                    {
                        if (part.Parent == parent)
                        {
                            result++;
                        }
                    }
                }
            }
            return(result);
        }
 private void VisitNamespaceParent(IIntermediateNamespaceParent nsParent, DefaultAssemblyFilenameVisitorContext context)
 {
     VisitTypeParent(nsParent, context);
     foreach (var @namespace in nsParent.Namespaces.ExclusivelyOnParent())
     {
         if (context.CurrentResult != null)
         {
             return;
         }
         @namespace.Value.Accept(this, context);
     }
     if (context.CurrentResult == null)
     {
         var  fields      = nsParent.Fields.ExclusivelyOnParent().Count() > 0;
         var  methods     = nsParent.Methods.ExclusivelyOnParent().Count() > 0;
         bool metadata    = false;
         var  assemTarget = nsParent as IIntermediateAssembly;
         if (assemTarget != null && assemTarget.IsRoot)
         {
             metadata = assemTarget.Metadata.Count > 0;
         }
         if (fields || methods || metadata)
         {
             int offset = 0;
             if (assemTarget != null &&
                 assemTarget.IsRoot)
             {
                 context.CurrentResult = @".\AssemblyInfo";
             }
             else
             {
                 context.CurrentResult = string.Format(@".\{0}", context.RootAssembly.Name);
             }
         }
     }
 }
Example #3
0
 /// <summary>
 /// Creates a new <see cref="IntermediateNamespaceDeclaration"/>
 /// with the <paramref name="name"/> and <paramref name="parent"/> provided.
 /// </summary>
 /// <param name="name">The <see cref="String"/> value representing the
 /// <see cref="IntermediateNamespaceDeclaration"/>'s name.</param>
 /// <param name="parent">The <see cref="IIntermediateNamespaceParent"/>
 /// which contains the <see cref="IntermediateNamespaceDeclaration"/>.</param>
 public IntermediateNamespaceDeclaration(string name, IIntermediateNamespaceParent parent)
     : base()
 {
     base.AssignName(name);
     this.parent = parent;
 }
Example #4
0
 /// <summary>
 /// Disposes the <see cref="IntermediateNamespaceDeclaration"/>
 /// </summary>
 /// <param name="disposing">whether to dispose the managed
 /// resources as well as the unmanaged resources.</param>
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (disposing)
         {
             lock (this.SyncObject)
             {
                 this.parent = null;
                 if (this.methods != null)
                 {
                     this.methods.Dispose();
                     this.methods = null;
                 }
                 if (this.fields != null)
                 {
                     this.fields.Dispose();
                     this.fields = null;
                 }
                 if (this.members != null)
                 {
                     if (this.IsRoot)
                     {
                         this.members.Dispose();
                     }
                     else
                     {
                         this.members.ConditionalRemove(this);
                     }
                     this.members = 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.types != null)
                 {
                     if (this.IsRoot)
                     {
                         this.types.Dispose();
                     }
                     else
                     {
                         this.types.ConditionalRemove(this);
                     }
                     this.types = null;
                 }
                 if (this.namespaces != null)
                 {
                     this.namespaces.Dispose();
                     this.namespaces = null;
                 }
                 this.scopeCoercions = null;
             }
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
Example #5
0
 /// <summary>
 /// Creates a new <see cref="IntermediateNamespaceDeclaration"/>
 /// instance with the root namespace declaration provided.
 /// </summary>
 /// <param name="rootDeclaration">The <see cref="IntermediateNamespaceDeclaration"/>
 /// which is the root instance.</param>
 /// <param name="parent">The <see cref="IIntermediateNamespaceParent"/>
 /// which contains the <see cref="IntermediateNamespaceDeclaration"/>.</param>
 public IntermediateNamespaceDeclaration(IntermediateNamespaceDeclaration rootDeclaration, IIntermediateNamespaceParent parent)
     : base(rootDeclaration)
 {
     this.parent = parent;
 }
Example #6
0
 protected void TranslateNamespaceParent(IIntermediateNamespaceParent parent)
 {
     this.TranslateFieldParent <ITopLevelFieldMember, IIntermediateTopLevelFieldMember, INamespaceParent, IIntermediateNamespaceParent>(parent);
     this.TranslateMethodSignatures(parent.Methods);
     this.TranslateTypeParent(parent);
 }
        /// <summary>
        /// Adds a new <see cref="IIntermediateNamespaceDeclaration"/> to the
        /// <see cref="IntermediateNamespaceDictionary"/>.
        /// </summary>
        /// <param name="path">The <see cref="String"/> representing the namespace's
        /// fully qualified path.</param>
        /// <returns>A new <see cref="IIntermediateNamespaceDeclaration"/>
        /// instance that results from the operation.</returns>
        /// <remarks>The <paramref name="name"/> is segmented and delimited by periods (Full Stops, U+002E)
        /// which make up the invidual sub-namespaces of the <see cref="IIntermediateNamespaceDeclaration"/>
        /// that results.</remarks>
        /// <exception cref="System.ArgumentException"><paramref name="path"/> exists
        /// already; <paramref name="path"/> is <see cref="String.Empty"/>; or
        /// <paramref name="path"/> consists of periods (Full Stops, U+002E) only.</exception>
        /// <exception cref="System.ArgumentNullException">thrown when <paramref name="name"/>
        /// is null.</exception>
        public virtual IIntermediateNamespaceDeclaration Add(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (path == string.Empty)
            {
                throw ThrowHelper.ObtainArgumentException(ArgumentWithException.path, ExceptionMessageId.ArgumentCannotBeEmpty, ThrowHelper.GetArgumentName(ArgumentWithException.path));
            }
            IIntermediateNamespaceCtorLanguageService ctorService = null;

            if (this.Parent != null && this.Parent.Assembly != null && this.Parent.Assembly.Provider != null)
            {
                this.Parent.Assembly.Provider.TryGetService(LanguageGuids.Services.IntermediateNamespaceCreatorService, out ctorService);
            }
            string separator = ctorService == null
                               ? "."
                               : ctorService.IdentitySeparator;

            if (path.Contains(separator))
            {
                var pathVariants = path.NamespacePathBreakdown();
                if (this.Parent is INamespaceDeclaration)
                {
                    pathVariants = pathVariants.Except(((INamespaceDeclaration)(this.Parent)).FullName.NamespacePathBreakdown(separator)).ToArray();
                }
                var names = pathVariants.ToArray();
                //It was comprised of dots only.
                if (names.Length == 0)
                {
                    throw ThrowHelper.ObtainArgumentException(ArgumentWithException.path, ExceptionMessageId.PathCannotBeDotsOnly);
                }
                if (names.Length == 1)
                {
                    return(this.Add(names[0].Name));
                }
                IIntermediateNamespaceParent parent = this.Parent;
                bool hadNonExistant = false;
                for (int i = 0; i < names.Length; i++)
                {
                    if (parent.Namespaces.ContainsKey(names[i]))
                    {
                        parent = parent.Namespaces[names[i]];
                    }
                    else
                    {
                        if (!hadNonExistant)
                        {
                            hadNonExistant = true;
                        }
                        parent = parent.Namespaces.Add(names[i].Name.GetNamespaceFinalPathPart(separator));
                    }
                }
                //The path already exists.
                if (!hadNonExistant)
                {
                    throw new ArgumentException(string.Format("The provided path '{0}' already exists at this level.", path), "path");
                }
                return((IIntermediateNamespaceDeclaration)parent);
            }
            else
            {
                if (this.ContainsKey(path))
                {
                    throw new ArgumentException(string.Format("The provided path {0} already exists at this level.", path), "path");
                }
                IIntermediateNamespaceDeclaration newNamespace =
                    ctorService != null
                    ? ctorService.New(path, this.Parent)
                    : new IntermediateNamespaceDeclaration(path, this.Parent);

                this._Add(newNamespace.UniqueIdentifier, newNamespace);
                return(newNamespace);
            }
        }
 /// <summary>
 /// Creates a new instance of an <see cref="IntermediateNamespaceDictionary"/>
 /// with the <paramref name="parent"/> provided.
 /// </summary>
 /// <param name="parent">The <see cref="IIntermediateNamespaceParent"/>
 /// which contains the <see cref="IntermediateNamespaceDictionary"/>
 /// and its elements.</param>
 /// <param name="toWrap">The <see cref="IntermediateNamespaceDictionary"/>
 /// to wrap the elements of.</param>
 public IntermediateNamespaceDictionary(IIntermediateNamespaceParent parent, IntermediateNamespaceDictionary toWrap) :
     base(toWrap)
 {
     this.parent = parent;
 }
 /// <summary>
 /// Creates a new instance of an <see cref="IntermediateNamespaceDictionary"/> with
 /// the <paramref name="parent"/> provided.
 /// </summary>
 /// <param name="parent">The <see cref="IIntermediateNamespaceParent"/>
 /// which contains the <see cref="IntermediateNamespaceDictionary"/>
 /// and its elements.</param>
 public IntermediateNamespaceDictionary(IIntermediateNamespaceParent parent) :
     base()
 {
     this.parent = parent;
 }