Beispiel #1
0
        // Builds, possibly nested, type name excluding any and all namespaces. Nested type name will have its
        // parent class names separated with dots.
        public virtual string GetNameWithoutNamespace()
        {
            if (Parent == null)
            {
                return(GetManagedName());
            }

            HierarchyElement parent = ParentElement;
            var segments            = new List <string> {
                GetManagedName()
            };

            while (parent != null)
            {
                if (parent is HierarchyNamespace)
                {
                    break;
                }

                segments.Add(parent.GetManagedName());
                parent = parent.ParentElement;
            }

            return(String.Join(".", segments));
        }
Beispiel #2
0
        protected FilesystemPath GetPathFor_FirstLevelThenFullShallow(string rootDirectory, HierarchyElement element)
        {
            string fullManagedName = element.GetManagedName(true);
            bool   isDirectory;
            string path = GetFirstNameSegment(fullManagedName);

            Logger.Debug($"Element: {element.FullName} (managed: {fullManagedName})");
            Logger.Debug($"Initial path: {path}");
            if (element is HierarchyNamespace)
            {
                Logger.Debug("Is namespace");
                isDirectory = true;
                path        = Path.Combine(path, fullManagedName);
            }
            else
            {
                var obj = element as HierarchyObject;
                if (obj == null)
                {
                    throw new InvalidOperationException("Only HierarchyObject and HierarchyNamespace instances can be used to compute output file name");
                }
                Logger.Debug("Is type");
                isDirectory = false;
                path        = Path.Combine(path, obj.GetNamespace(), obj.GetNameWithoutNamespace());
            }
            Logger.Debug($"Final relative path: {path}");
            Logger.Debug(String.Empty);
            return(GetFilePath(rootDirectory, path, isDirectory));
        }
Beispiel #3
0
        protected virtual void GenerateNamespaceMember(HierarchyNamespace ns, HierarchyElement element, string outputDirectory)
        {
            FilesystemPath path = Context.OutputPathProvider.GetPathFor(outputDirectory, element);

            if (String.IsNullOrEmpty(path?.FullPath))
            {
                Logger.Warning($"Unable to generate output for element {element.GetType ().FullName} ({element.GetManagedName (true) ?? element.FullName}) since no full path was given (at {element.GetLocation ()})");
                return;
            }

            if (path.IsDirectory)
            {
                throw new InvalidOperationException($"Namespace member must be written to a file ({ns.FullName})");
            }

            EnsureDirectory(Path.GetDirectoryName(path.FullPath));
            CheckOverwrite(path.FullPath);

            using (Stream fs = File.Open(path.FullPath, FileMode.Create)) {
                using (StreamWriter writer = new StreamWriter(fs, Context.FileEncoding)) {
                    WriteFileHeader(ns, writer);
                    OutputNamespaceMember(element, writer, path.FullPath);
                    WriteFileFooter(ns, writer);
                }
            }
        }
Beispiel #4
0
 protected virtual void GenerateNamespaceMember(HierarchyElement element, TextWriter writer, string outputFileName)
 {
     Logger.Debug($"Generating {element.GetManagedName (true)} in namespace output file: {outputFileName}");
     OutputNamespaceMember(element, writer, outputFileName);
 }