public XamlLazyApplyBlockIIndentedStringBuilder(IIndentedStringBuilder source, string closureName, string applyPrefix, string delegateType)
 {
     _closureName  = closureName;
     _source       = source;
     _applyPrefix  = applyPrefix;
     _delegateType = delegateType;
 }
 public XamlLazyApplyBlockIIndentedStringBuilder(IIndentedStringBuilder source, string closureName, string?applyPrefix, string?delegateType, IDisposable?parentDisposable = null)
 {
     _closureName      = closureName;
     _source           = source;
     _applyPrefix      = applyPrefix;
     _delegateType     = delegateType;
     _parentDisposable = parentDisposable;
 }
        public static IDisposable Indent(this IIndentedStringBuilder builder, string opening, string closing = null)
        {
            builder.AppendLine2(opening);
            var block = builder.Indent();

            return(new DisposableAction(() =>
            {
                block.Dispose();
                if (closing != null)
                {
                    builder.AppendLine2(closing);
                }
            }));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Outputs SuppressMessage attributes using the provided <see cref="IndentedStringBuilder"/>, and a list of suppressions.
        /// </summary>
        /// <param name="writer">An <see cref="IndentedStringBuilder"/> instance.</param>
        /// <param name="analyzerSuppressions">A list of analyzers definitions in the format of "Category|AnalyzerId"</param>
        internal static void Generate(IIndentedStringBuilder writer, string[] analyzerSuppressions)
        {
            var suppresses = from suppress in analyzerSuppressions
                             let parts = suppress.Split('|', '-')
                                         where parts.Length == 2
                                         let category                   = parts[0]
                                                                 let id = parts[1]
                                                                          select "[global::System.Diagnostics.CodeAnalysis.SuppressMessage(\"{0}\", \"{1}\", Justification=\"Generated code\")]".InvariantCultureFormat(category, id);

            foreach (var suppress in suppresses)
            {
                writer.AppendLineInvariant(suppress);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Outputs #pragma warning disable statements using the provided <see cref="IndentedStringBuilder"/>, and a list of suppressions.
        /// </summary>
        /// <param name="writer">An <see cref="IndentedStringBuilder"/> instance.</param>
        /// <param name="analyzerSuppressions">A list of analyzers definitions in the format of "Category|AnalyzerId"</param>
        internal static void GenerateCSharpPragmaSupressions(IIndentedStringBuilder writer, string[] analyzerSuppressions)
        {
            var suppresses = from suppress in analyzerSuppressions
                             let parts = suppress.Split('|', '-')
                                         where parts.Length == 2
                                         let category = parts[0]
                                                        where category == "csharp"
                                                        let id = parts[1]
                                                                 select $"#pragma warning disable {id}";

            foreach (var suppress in suppresses)
            {
                writer.AppendLineInvariant(suppress);
            }
        }
Ejemplo n.º 6
0
        public static Stack <IDisposable> AddToIndentedStringBuilder(this INamedTypeSymbol namedTypeSymbol, IIndentedStringBuilder builder, Action <IIndentedStringBuilder>?beforeClassHeaderAction = null)
        {
            var     stack  = new Stack <string>();
            ISymbol symbol = namedTypeSymbol;

            while (symbol != null)
            {
                if (symbol is INamespaceSymbol namespaceSymbol)
                {
                    if (!namespaceSymbol.IsGlobalNamespace)
                    {
                        stack.Push($"namespace {namespaceSymbol}");
                    }

                    break;
                }
                else if (symbol is INamedTypeSymbol namedSymbol)
                {
                    stack.Push(GetDeclarationHeaderFromNamedTypeSymbol(namedSymbol));
                }
                else
                {
                    throw new InvalidOperationException($"Unexpected symbol type {symbol}");
                }

                symbol = symbol.ContainingSymbol;
            }

            var outputDisposableStack = new Stack <IDisposable>();

            while (stack.Count > 0)
            {
                if (stack.Count == 1)
                {
                    // Only the original symbol is left (usually a class header). Execute the given action before adding the class (usually this adds attributes).
                    beforeClassHeaderAction?.Invoke(builder);
                }

                outputDisposableStack.Push(builder.BlockInvariant(stack.Pop()));
            }

            return(outputDisposableStack);
        }
Ejemplo n.º 7
0
 public void ExtendApiClientConstructor(IIndentedStringBuilder builder, ApiClientModule apiClientModule)
 {
     builder.AppendLine("foo.extendConstructor();");
 }
 public static IDisposable BlockInvariant(this IIndentedStringBuilder builder, bool braces, string pattern, params object[] parameters)
 {
     return(builder.Block(CultureInfo.InvariantCulture, braces, pattern, parameters));
 }
 public static void AppendLine(this IIndentedStringBuilder builder, IFormatProvider formatProvider, string pattern, params object[] replacements)
 {
     builder.AppendFormat(formatProvider, pattern, replacements);
     builder.AppendLine();
 }
 public static void AppendFormatInvariant(this IIndentedStringBuilder builder, string pattern, params object[] replacements)
 {
     builder.AppendFormat(CultureInfo.InvariantCulture, pattern, replacements);
 }
 public static IDisposable BlockInvariant(this IIndentedStringBuilder builder, string pattern, params object[] parameters)
 {
     return(BlockInvariant(builder, true, pattern, parameters));
 }
Ejemplo n.º 12
0
 public void ExtendApiClientClass(IIndentedStringBuilder builder, ApiClientModule apiClientModule)
 {
     builder.AppendLine("public bar() { return foo.bar(); }");
 }
 public static void AppendLineInvariant(this IIndentedStringBuilder builder, int indentLevel, string pattern, params object[] replacements)
 {
     builder.AppendLine(CultureInfo.InvariantCulture, indentLevel, pattern, replacements);
 }
 /// <summary>
 /// Sane version of <see cref="IndentedStringBuilder.AppendLine(string)"/> that actually appends a newline.
 /// </summary>
 /// <param name="text">The string to append.</param>
 public static void AppendLine2(this IIndentedStringBuilder builder, string text)
 {
     builder.AppendLine(text);
     builder.AppendLine();
 }
Ejemplo n.º 15
0
 public void WriteCodeAfterApiClientClass(IIndentedStringBuilder builder, ApiClientModule apiClientModule)
 {
     builder.AppendLine("foo.after();");
 }
Ejemplo n.º 16
0
 public void WriteCodeBeforeApiClientClass(IIndentedStringBuilder builder, ApiClientModule apiClientModule)
 {
     builder.AppendLine("foo.before();");
 }
Ejemplo n.º 17
0
 public void WriteImports(IIndentedStringBuilder builder, ApiClientModule apiClientModule)
 {
     builder.AppendLine("import { foo } from 'bar'");
 }
Ejemplo n.º 18
0
 public ApiMethodGenerator(ApiMethod apiMethod, IIndentedStringBuilder result, TypeMapping typeMapping)
 {
     _apiMethod   = apiMethod;
     _result      = result;
     _typeMapping = typeMapping;
 }