Пример #1
0
        /// <summary>
        /// Gets the closing string for the specified code item.
        /// </summary>
        /// <param name="codeItem">The code item.</param>
        /// <returns>The closing string, otherwise null.</returns>
        private static string GetClosingString(ICodeItemParameters codeItem)
        {
            if (codeItem is CodeItemProperty property)
            {
                return(property.IsIndexer ? "]" : null);
            }

            return(")");
        }
        /// <summary>
        /// Gets the closing string for the specified code item.
        /// </summary>
        /// <param name="codeItem">The code item.</param>
        /// <returns>The closing string, otherwise null.</returns>
        private static string GetClosingString(ICodeItemParameters codeItem)
        {
            var property = codeItem as CodeItemProperty;

            if (property != null)
            {
                return(property.IsIndexer ? "]" : null);
            }

            return(")");
        }
        /// <summary>
        /// Creates the inlines for the specified code item's parameters.
        /// </summary>
        /// <param name="codeItem">The code item.</param>
        /// <returns>The inlines representing the parameters.</returns>
        private IEnumerable <Inline> CreateInlinesForParameters(ICodeItemParameters codeItem)
        {
            var inlines = new List <Inline>();

            var opener = GetOpeningString(codeItem);

            if (opener != null)
            {
                inlines.Add(CreateItalicRun(opener));
            }

            bool isFirst = true;

            try
            {
                foreach (var param in codeItem.Parameters)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        inlines.Add(CreateItalicRun(", "));
                    }

                    try
                    {
                        inlines.Add(CreateTypeRun(TypeFormatHelper.Format(param.Type.AsString) + " "));
                        inlines.Add(CreateItalicRun(param.Name));
                    }
                    catch (Exception)
                    {
                        inlines.Add(CreateItalicRun("?"));
                    }
                }
            }
            catch (Exception)
            {
                inlines.Add(CreateItalicRun("?"));
            }

            var closer = GetClosingString(codeItem);

            if (closer != null)
            {
                inlines.Add(CreateItalicRun(closer));
            }

            return(inlines);
        }
        /// <summary>
        /// Gets the opening string for the specified code item.
        /// </summary>
        /// <param name="codeItem">The code item.</param>
        /// <returns>The opening string, otherwise null.</returns>
        private static string GetOpeningString(ICodeItemParameters codeItem)
        {
            var property = codeItem as CodeItemProperty;
            if (property != null)
            {
                return property.IsIndexer ? "[" : null;
            }

            return "(";
        }
        /// <summary>
        /// Creates the inlines for the specified code item's parameters.
        /// </summary>
        /// <param name="codeItem">The code item.</param>
        /// <returns>The inlines representing the parameters.</returns>
        private IEnumerable<Inline> CreateInlinesForParameters(ICodeItemParameters codeItem)
        {
            var inlines = new List<Inline>();

            var opener = GetOpeningString(codeItem);
            if (opener != null)
            {
                inlines.Add(CreateItalicRun(opener));
            }

            bool isFirst = true;

            try
            {
                foreach (var param in codeItem.Parameters)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        inlines.Add(CreateItalicRun(", "));
                    }

                    try
                    {
                        inlines.Add(CreateTypeRun(TypeFormatHelper.Format(param.Type.AsString) + " "));
                        inlines.Add(CreateItalicRun(param.Name));
                    }
                    catch (Exception)
                    {
                        inlines.Add(CreateItalicRun("?"));
                    }
                }
            }
            catch (Exception)
            {
                inlines.Add(CreateItalicRun("?"));
            }

            var closer = GetClosingString(codeItem);
            if (closer != null)
            {
                inlines.Add(CreateItalicRun(closer));
            }

            return inlines;
        }