예제 #1
0
        /// <summary>
        /// Gets a relative path from this folder to another one.
        /// This folder and the other one must belong to the same <see cref="TypeScriptCodeGenerationContext"/>
        /// otherwise an <see cref="InvalidOperationException"/> is thrown.
        /// </summary>
        /// <param name="f">The folder to target.</param>
        /// <returns>The relative path from this one to the other one.</returns>
        public NormalizedPath GetRelativePathTo(TypeScriptFolder f)
        {
            var            source = this;
            NormalizedPath result = new NormalizedPath();

            do
            {
                int below = source.FindBelow(f);
                if (below >= 0)
                {
                    if (below == 0)
                    {
                        return(result);
                    }
                    if (below == 1)
                    {
                        return(result.AppendPart(f.Name));
                    }
                    var path = new string[below];
                    var idx  = path.Length;
                    do
                    {
                        path[--idx] = f.Name;
                        f           = f.Parent !;
                    }while(idx > 0);
                    foreach (var p in path)
                    {
                        result = result.AppendPart(p);
                    }
                    return(result);
                }
                result = result.AppendPart("..");
            }while((source = source.Parent !) != null);
            throw new InvalidOperationException("TypeScriptFolder must belong to the same TypeScriptCodeGenerationContext.");
        }
예제 #2
0
 internal TypeScriptFolder(TypeScriptFolder parent, string name)
 {
     _g                 = parent._g;
     Parent             = parent;
     Name               = name;
     _next              = parent._firstChild;
     parent._firstChild = this;
 }
예제 #3
0
 internal TypeScriptFile(TypeScriptFolder folder, string name)
 {
     Folder            = folder;
     Name              = name;
     _next             = folder._firstFile;
     folder._firstFile = this;
     Imports           = new FileImportCodePart(this);
     Body              = new FileBodyCodePart(this);
 }
 /// <summary>
 /// Initializes a new <see cref="TypeScriptCodeGenerationContext"/>.
 /// </summary>
 /// <param name="outputPaths">Non empty set of output paths.</param>
 /// <param name="pascalCase">Whether PascalCase identifiers should be generated instead of camelCase.</param>
 public TypeScriptCodeGenerationContext(IEnumerable <NormalizedPath> outputPaths, bool pascalCase)
 {
     if (outputPaths == null || !outputPaths.Any())
     {
         throw new ArgumentException("Must not be null or empty.", nameof(outputPaths));
     }
     _paths      = new HashSet <NormalizedPath>(outputPaths);
     _pascalCase = pascalCase;
     Root        = new TypeScriptFolder(this);
 }
예제 #5
0
        /// <summary>
        /// Finds a folder below this one by returning its depth.
        /// This returns 0 when this is the same as <paramref name="other"/>
        /// and -1 if other is not subordinated to this folder.
        /// </summary>
        /// <param name="other">The other folder to locate.</param>
        /// <returns>The depth of the other folder below this one.</returns>
        public int FindBelow(TypeScriptFolder other)
        {
            int depth          = 0;
            TypeScriptFolder?c = other;

            while (c != this)
            {
                ++depth;
                c = c.Parent;
                if (c == null)
                {
                    return(-1);
                }
            }
            return(depth);
        }