Beispiel #1
0
        static string GetContextLocation(HierarchyElement context)
        {
            if (context == null)
            {
                return(String.Empty);
            }

            string ret      = $" Called on behalf of: {context.FullName}";
            string location = context.GetLocation();

            if (!String.IsNullOrEmpty(location))
            {
                ret += $" at {location}";
            }

            return(ret);
        }
Beispiel #2
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 #3
0
        protected virtual T SelectNewParent <T> (HierarchyElement element) where T : HierarchyElement
        {
            if (element == null)
            {
                return(null);
            }

            if (String.IsNullOrEmpty(element.FullName))
            {
                throw new InvalidOperationException("Each element must have a full name");
            }

            if (TypeIndex.Count == 0)
            {
                Logger.Warning($"Unable to select new parent for element {element.Name}, type index does not exist");
                return(null);
            }

            // The way API description is constructed we can check whether a class/interface/enum is nested
            // by simply looking at its "namespace" name and checking whether it corresponds to another
            // class or interfaces
            string nsOrTypeName = Helpers.GetTypeNamespace(element.FullName);

            if (String.IsNullOrEmpty(nsOrTypeName))
            {
                return(null);
            }

            try {
                HierarchyElement maybeParent = TypeIndex.Lookup(nsOrTypeName);
                if (maybeParent == null)
                {
                    return(null);
                }

                var ret = maybeParent as T;
                if (ret == null)
                {
                    return(null);
                }

                return(ret);
            } catch {
                Logger.Fatal($"Error selecting new parent for element '{element.FullName}' ({element.GetLocation ()})");
                throw;
            }
        }