예제 #1
0
        /// <summary>Initializes a new instance of the <see cref="MarkdownReference"/> class.</summary>
        /// <param name="memberInfo">The member info type.</param>
        /// <param name="id">The source url path of the image, website or link to file.</param>
        /// <param name="settings">The report settings.</param>
        /// <exception cref="ArgumentNullException">name - The markdown element name cannot be null or empty.</exception>
        public MarkdownTypeId(MemberInfoTypes memberInfo, string id, ReportSettings settings) : base($@"{id} Image", Path.Combine(settings.ImageRepository, $@"{id}{Constants.ImageFilePNGExtension}"), $@"Public {id}")
        {
            MemberInfo = memberInfo;
            ID         = id;
            Settings   = settings;

            ImageReference  = $@"{id}{ImageRef}";
            SourceReference = $@"{id}{SourceRef}";

            ImageType       = MarkdownImage.CreateImageType0(this);
            ImageTypeSource = MarkdownImage.CreateImageTypeSource(this);
        }
예제 #2
0
        /// <summary>Generates the category section for the members info.</summary>
        /// <param name="sectionInfoTypes">The section kind.</param>
        /// <param name="categoryHeader">The category header name.</param>
        /// <param name="tableName">The table name.</param>
        /// <param name="settings">The image directory.</param>
        /// <param name="items">The table row items.</param>
        /// <returns>The <see cref="string"/>.</returns>
        private static string GenerateSection(MemberInfoTypes sectionInfoTypes, string categoryHeader, string tableName, ReportSettings settings, List <HierarchyNode> items)
        {
            const string DescriptionHeader = "Description";
            const string ValuesHeader      = "Values";

            string basePath;
            char   pathDivider;

            if (settings.FileRepositoryIsUrl)
            {
                pathDivider = Path.AltDirectorySeparatorChar;

                // Retrieve the trimmed relative path
                string parentUrl     = TextUtil.GetParentUriString(new Uri(settings.ImageRepository));
                string relativePath  = TextUtil.GetRelativeURIPath(parentUrl, settings.ImageRepository);
                string formattedPath = relativePath.Substring(1, relativePath.Length - 2);

                // Formats the path to a url from string
                basePath = $@"{formattedPath}";
            }
            else
            {
                pathDivider = Path.DirectorySeparatorChar;

                // Return the relative path
                string dirPath = Path.GetDirectoryName(settings.BuildPath);

                string relativePath = TextUtil.GetRelativePath(settings.ImageRepository, dirPath);

                // Format the path to scope into the image directory for retrieving the images from the local system.
                basePath = $@".\{relativePath}";
            }

            string imageSource = $@"{basePath}{pathDivider}{tableName}{Constants.ImageFilePNGExtension}";

            string memberImageText = HtmlUtil.GenerateHTMLImageCode(imageSource, tableName, new Size(16, 16));

            // Create the markdown table layout.
            var columns = new List <string>();
            var rows    = new List <string>();

            // Create the top left section. Add an empty buffer image to keep the table cells at a minimum size to prevent hiding the image cells when during text wrapping.

            columns.Add(string.Format("<img src={0}file://null{0} width={0}{1}{0} height={0}0{0} alt ={0}{0} />", Constants.Quotes, 64));
            columns.Add(tableName);
            columns.Add(DescriptionHeader);

            // Determine the member kind.
            switch (sectionInfoTypes)
            {
            case MemberInfoTypes.Class:
            {
                // Create section separators.
                const string sectionSeparators = TableDividerSet0;
                rows.Add(sectionSeparators);

                // Create section items content.
                foreach (HierarchyNode entry in items)
                {
                    string itemName        = entry.Name;
                    string itemDescription = DocumentationExtensions.GetSummary(entry.NodeType);

                    if (string.IsNullOrEmpty(itemDescription))
                    {
                        itemDescription = MissingDocumentationText;
                    }

                    string rowItemName = $"{memberImageText} {MarkdownSeparator} {itemName} {MarkdownSeparator} {itemDescription}";

                    rows.Add(rowItemName);
                }

                break;
            }

            case MemberInfoTypes.Delegate:
            {
                // Create section separators.
                const string sectionSeparators = TableDividerSet0;
                rows.Add(sectionSeparators);

                // Create section items content.
                foreach (HierarchyNode entry in items)
                {
                    string itemName        = entry.Name;
                    string itemDescription = DocumentationExtensions.GetSummary(entry.NodeType);

                    if (string.IsNullOrEmpty(itemDescription))
                    {
                        itemDescription = MissingDocumentationText;
                    }

                    string rowItemName = $"{memberImageText} {MarkdownSeparator} {itemName} {MarkdownSeparator} {itemDescription}";

                    rows.Add(rowItemName);
                }

                break;
            }

            case MemberInfoTypes.Enumerator:
            {
                columns.Add(ValuesHeader);

                // Create section separators.
                const string sectionSeparators = TableDividerSet1;
                rows.Add(sectionSeparators);

                // Create section items content.
                foreach (HierarchyNode entry in items)
                {
                    string itemName        = entry.Name;
                    string itemDescription = DocumentationExtensions.GetSummary(entry.NodeType);

                    if (string.IsNullOrEmpty(itemDescription))
                    {
                        itemDescription = MissingDocumentationText;
                    }

                    string enumValues = TypesUtil.GetEnumeratorValues(entry.NodeType);

                    string rowItemName = $"{memberImageText} {MarkdownSeparator} {itemName} {MarkdownSeparator} {itemDescription} {MarkdownSeparator} {enumValues}.";

                    rows.Add(rowItemName);
                }

                break;
            }

            case MemberInfoTypes.Structure:
            {
                // Create section separators.
                const string sectionSeparators = TableDividerSet0;
                rows.Add(sectionSeparators);

                // Create section items content.
                foreach (HierarchyNode entry in items)
                {
                    string itemName        = entry.Name;
                    string itemDescription = DocumentationExtensions.GetSummary(entry.NodeType);

                    if (string.IsNullOrEmpty(itemDescription))
                    {
                        itemDescription = MissingDocumentationText;
                    }

                    string rowItemName = $"{memberImageText} {MarkdownSeparator} {itemName} {MarkdownSeparator} {itemDescription}";

                    rows.Add(rowItemName);
                }

                break;
            }

            case MemberInfoTypes.Interface:
            {
                // Create section separators.
                const string sectionSeparators = TableDividerSet0;
                rows.Add(sectionSeparators);

                // Create section items content.
                foreach (HierarchyNode entry in items)
                {
                    string itemName        = entry.Name;
                    string itemDescription = DocumentationExtensions.GetSummary(entry.NodeType);

                    if (string.IsNullOrEmpty(itemDescription))
                    {
                        itemDescription = MissingDocumentationText;
                    }

                    string rowItemName = $"{memberImageText} {MarkdownSeparator} {itemName} {MarkdownSeparator} {itemDescription}";

                    rows.Add(rowItemName);
                }

                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(sectionInfoTypes), sectionInfoTypes, null);
            }
            }

            // Generate markdown table.
            StringBuilder sectionBuilder = new StringBuilder();

            // Create the header.
            sectionBuilder.AppendLine(MarkdownHeader.CreateHeader(categoryHeader, 3));

            // Create the table.
            string table = new MarkdownTable(columns, rows).MarkdownContentText;

            sectionBuilder.Append(table);

            return(sectionBuilder.ToString());
        }
        /// <summary>Generates this instance.</summary>
        private void Generate()
        {
            string generatedText;

            string memberInfoTypeName = Cb_GenerateMemberType.SelectedItem.ToString();

            MemberInfoTypes memberInfoTypes = (MemberInfoTypes)Enum.Parse(typeof(MemberInfoTypes), memberInfoTypeName);

            string cref = DescriptionGeneratorBase.GenerateCodeReference($@"{GeneratorDescriptor.Name}", DescriptionGeneratorBase.CodeReferenceTypes.See);

            var parametersList = parameterInfoEditorDialog.Items;

            // Handle the generation provider methods to use
            switch (memberInfoTypes)
            {
            case MemberInfoTypes.Class:
            {
                // Handles the class or constructor description generation
                if (classGenerationPage.IsConstructor)
                {
                    generatedText = DescriptionGeneratorBase.GenerateConstructor(GeneratorDescriptor.Name, classGenerationPage.IsPrivate, parametersList, GeneratorDescriptor.Remarks);
                }
                else
                {
                    generatedText = DescriptionGeneratorBase.GenerateSummary($@"The {cref} class.", GeneratorDescriptor.Remarks);
                }

                if (Cb_Inherit.Checked)
                {
                    string inheritText = DescriptionGeneratorBase.GenerateCodeReference(Tb_Inheritance.Text, DescriptionGeneratorBase.CodeReferenceTypes.SeeAlso);
                    generatedText += string.Format("{0}{1} {2}", Environment.NewLine, DescriptionGeneratorBase.CommentDocumentation, inheritText);
                }

                break;
            }

            case MemberInfoTypes.Event:
            {
                generatedText = DescriptionGeneratorBase.GenerateEvent(GeneratorDescriptor.Name, parametersList, GeneratorDescriptor.Remarks);
                break;
            }

            case MemberInfoTypes.Field:
            {
                generatedText = DescriptionGeneratorBase.GenerateSummary($@"The {cref}.", GeneratorDescriptor.Remarks);
                break;
            }

            case MemberInfoTypes.Method:
            {
                generatedText = DescriptionGeneratorBase.GenerateMethod(GeneratorDescriptor.Name, GeneratorDescriptor.ReturnTypeName, parametersList, GeneratorDescriptor.Remarks);
                break;
            }

            case MemberInfoTypes.Property:
            {
                generatedText = DescriptionGeneratorBase.GenerateProperty(GeneratorDescriptor.Name, GeneratorDescriptor.ReturnTypeName, propertyGenerationPage.Get, propertyGenerationPage.Set, GeneratorDescriptor.Remarks);
                break;
            }

            case MemberInfoTypes.Delegate:
            {
                generatedText = DescriptionGeneratorBase.GenerateDelegate(GeneratorDescriptor.Name, GeneratorDescriptor.Remarks);
                break;
            }

            case MemberInfoTypes.Enumerator:
            {
                generatedText = DescriptionGeneratorBase.GenerateSummary($@"The {cref} enumerator.");
                break;
            }

            case MemberInfoTypes.Structure:
            {
                generatedText = DescriptionGeneratorBase.GenerateSummary($@"The {cref} structure.");

                if (Cb_Inherit.Checked)
                {
                    string inheritText = DescriptionGeneratorBase.GenerateCodeReference(Tb_Inheritance.Text, DescriptionGeneratorBase.CodeReferenceTypes.SeeAlso);
                    generatedText += Environment.NewLine + inheritText;
                }

                break;
            }

            case MemberInfoTypes.Interface:
            {
                generatedText = DescriptionGeneratorBase.GenerateSummary($@"The {cref} interface.");

                if (Cb_Inherit.Checked)
                {
                    string inheritText = DescriptionGeneratorBase.GenerateCodeReference(Tb_Inheritance.Text, DescriptionGeneratorBase.CodeReferenceTypes.SeeAlso);
                    generatedText += Environment.NewLine + inheritText;
                }

                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException();
            }
            }

            Rtb_Output.Text  = generatedText;
            Btn_Copy.Enabled = true;
        }
예제 #4
0
        /// <summary>Gets the index of the image.</summary>
        /// <param name="source">The source type.</param>
        /// <returns>The <see cref="int"/>.</returns>
        public static int GetMemberImageIndex(MemberInfoTypes source)
        {
            /* The Assembly Explorer Tree View ImageList icons index table:
             *
             * 0 = Folder
             * 1 = Namespace
             * 2 = Class
             * 3 = Delegate
             * 4 = Enumerator
             * 5 = Event
             * 6 = Interface
             * 7 = Method
             * 8 = Structure
             * 9 = Constructor
             * 10 = Field
             * 11 = Property
             *
             */

            int index;

            switch (source)
            {
            case MemberInfoTypes.Event:
            {
                index = 5;
                break;
            }

            case MemberInfoTypes.Field:
            {
                index = 10;
                break;
            }

            case MemberInfoTypes.Method:
            {
                index = 7;
                break;
            }

            case MemberInfoTypes.Property:
            {
                index = 11;
                break;
            }

            case MemberInfoTypes.Class:
            {
                index = 2;
                break;
            }

            case MemberInfoTypes.Delegate:
            {
                index = 3;
                break;
            }

            case MemberInfoTypes.Enumerator:
            {
                index = 4;
                break;
            }

            case MemberInfoTypes.Structure:
            {
                index = 8;
                break;
            }

            case MemberInfoTypes.Interface:
            {
                index = 6;
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(source), source, null);
            }
            }

            return(index);
        }
예제 #5
0
        /// <summary>Saves the specified image member type to the specified output path.</summary>
        /// <param name="outputFolder">The output folder to save to.</param>
        /// <param name="fileName">The image file name to save as.</param>
        /// <param name="memberInfoTypes">Kind of the member.</param>
        /// <exception cref="ArgumentNullException">Thrown when the path is null or empty.</exception>
        /// <exception cref="ArgumentOutOfRangeException"> Thrown when the memberType or memberKind is null.</exception>
        public static void ExportMemberTypeImage(string outputFolder, string fileName, MemberInfoTypes memberInfoTypes)
        {
            if (string.IsNullOrEmpty(outputFolder))
            {
                throw new ArgumentNullException(nameof(outputFolder), @"The output path cannot be null or empty.");
            }

            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }

            try
            {
                Image imageType = ResolveMemberTypeImage(memberInfoTypes);

                string fullName        = fileName + Constants.ImageFilePNGExtension;
                string destinationPath = Path.Combine(outputFolder, fullName);

                // Save image to file.
                imageType.Save(destinationPath, ImageFormat.Png);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
예제 #6
0
        /// <summary>Resolves the member type image.</summary>
        /// <param name="memberInfoTypes">The member information types.</param>
        /// <returns>The <see cref="Image"/>.</returns>
        /// <exception cref="ArgumentOutOfRangeException">memberInfoTypes - null</exception>
        public static Image ResolveMemberTypeImage(MemberInfoTypes memberInfoTypes)
        {
            string memberName;

            // Determine the image to extract.
            switch (memberInfoTypes)
            {
            case MemberInfoTypes.Class:
            {
                memberName = "Class";
                break;
            }

            case MemberInfoTypes.Delegate:
            {
                memberName = "Delegate";
                break;
            }

            case MemberInfoTypes.Enumerator:
            {
                memberName = "Enumerator";
                break;
            }

            case MemberInfoTypes.Structure:
            {
                memberName = "Structure";
                break;
            }

            case MemberInfoTypes.Interface:
            {
                memberName = "Interface";
                break;
            }

            case MemberInfoTypes.Event:
            {
                memberName = "Event";
                break;
            }

            case MemberInfoTypes.Field:
            {
                memberName = "Field";
                break;
            }

            case MemberInfoTypes.Method:
            {
                memberName = "Method";
                break;
            }

            case MemberInfoTypes.Property:
            {
                memberName = "Property";
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(memberInfoTypes), memberInfoTypes, null);
            }
            }

            string fullResourceName = memberName + Constants.ImageFilePNGExtension;

            // Get the assembly to extract the resource images from.
            Assembly assembly         = typeof(Constants).Assembly;
            string   resourceBasePath = assembly.GetResourceBasePath(fullResourceName);

            // Extract to image.
            Image extractToImage = ResourceUtils.ExtractToImage(assembly, resourceBasePath);

            return(extractToImage);
        }