Beispiel #1
0
 /// <summary>
 /// Generates code for the specified Code Document Object Model (CodeDOM) type declaration and
 /// outputs it to a string using the specified options.
 /// </summary>
 /// <param name="type">A <see cref="CodeTypeDeclaration"/> that indicates the type to generate code for.</param>
 /// <param name="options">A <see cref="SafeCodeGeneratorOptions"/> that indicates the options to use for generating code.</param>
 /// <returns>The generated code.</returns>
 public string GenerateCodeFromType(CodeTypeDeclaration type, SafeCodeGeneratorOptions options)
 {
     using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture))
     {
         this.GenerateCodeFromType(type, writer, options);
         return(this.RewriteExtensionMethod(writer.ToString()));
     }
 }
Beispiel #2
0
 /// <summary>
 /// Generates code for the specified Code Document Object Model (CodeDOM) statement and
 /// outputs it to a string using the specified options.
 /// </summary>
 /// <param name="statement">A <see cref="CodeStatement"/> containing the CodeDOM elements to translate.</param>
 /// <param name="options">A <see cref="SafeCodeGeneratorOptions"/> that indicates the options to use for generating code.</param>
 /// <returns>The generated code.</returns>
 public string GenerateCodeFromStatement(CodeStatement statement, SafeCodeGeneratorOptions options)
 {
     using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture))
     {
         this.GenerateCodeFromStatement(statement, writer, options);
         return(this.RewriteExtensionMethod(writer.ToString()));
     }
 }
Beispiel #3
0
 /// <summary>
 /// Generates code for the specified Code Document Object Model (CodeDOM) namespace and
 /// outputs it to a string using the specified options.
 /// </summary>
 /// <param name="ns">A <see cref="CodeNamespace"/> that indicates the namespace to generate code for.</param>
 /// <param name="options">A <see cref="SafeCodeGeneratorOptions"/> that indicates the options to use for generating code.</param>
 /// <returns>The generated code.</returns>
 public string GenerateCodeFromNamespace(CodeNamespace ns, SafeCodeGeneratorOptions options)
 {
     using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture))
     {
         this.GenerateCodeFromNamespace(ns, writer, options);
         return(this.RewriteExtensionMethod(writer.ToString()));
     }
 }
Beispiel #4
0
 /// <summary>
 /// Generates code for the specified Code Document Object Model (CodeDOM) expression and outputs it to a string
 /// using the specified options.
 /// </summary>
 /// <param name="expression">A <see cref="CodeExpression"/> that indicates the expression to generate code for.</param>
 /// <param name="options">A <see cref="SafeCodeGeneratorOptions"/> that indicates the options to use for generating code.</param>
 /// <returns>The generated code.</returns>
 public string GenerateCodeFromExpression(CodeExpression expression, SafeCodeGeneratorOptions options)
 {
     using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture))
     {
         this.GenerateCodeFromExpression(expression, writer, options);
         return(this.RewriteExtensionMethod(writer.ToString()));
     }
 }
Beispiel #5
0
 public virtual void GenerateCodeFromType(CodeTypeDeclaration type, TextWriter writer, SafeCodeGeneratorOptions options)
 {
     using (StringWriter wrappedWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         this.WrappedCodeGenerator.GenerateCodeFromType(this.Rewriter.Rewrite(type), wrappedWriter, options);
         writer.Write(this.RewriteExtensionMethod(wrappedWriter.ToString()));
     }
 }
Beispiel #6
0
 public virtual void GenerateCodeFromStatement(CodeStatement statement, TextWriter writer, SafeCodeGeneratorOptions options)
 {
     using (var wrappedWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         this.WrappedCodeGenerator.GenerateCodeFromStatement(this.Rewriter.Rewrite(statement), wrappedWriter, options);
         writer.Write(this.RewriteExtensionMethod(wrappedWriter.ToString()));
     }
 }
Beispiel #7
0
 public virtual void GenerateCodeFromExpression(CodeExpression expression, TextWriter writer, SafeCodeGeneratorOptions options)
 {
     using (StringWriter wrappedWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         this.WrappedCodeGenerator.GenerateCodeFromExpression(this.Rewriter.Rewrite(expression), wrappedWriter, options);
         writer.Write(this.RewriteExtensionMethod(wrappedWriter.ToString()));
     }
 }
Beispiel #8
0
 public virtual void GenerateCodeFromCompileUnit(CodeCompileUnit compileUnit, TextWriter writer, SafeCodeGeneratorOptions options)
 {
     using (var wrappingWriter = new StringWriter(CultureInfo.InvariantCulture))
     {
         this.WrappedCodeGenerator.GenerateCodeFromCompileUnit(this.Rewriter.Rewrite(compileUnit), wrappingWriter, options);
         string rewrittenResults = this.RewriteExtensionMethod(wrappingWriter.ToString());
         writer.Write(rewrittenResults);
     }
 }
        /// <summary>
        /// Generates code for the specified Code Document Object Model (CodeDOM) compilation unit and
        /// outputs it to the specified a string.
        /// </summary>
        /// <param name="codeUnit">A <see cref="CodeCompileUnit"/> to generate code for.</param>
        /// <returns>The generated code.</returns>
        protected virtual string GenerateCodeFromCompileUnit(CodeCompileUnit codeUnit)
        {
            ExtendedCodeGenerator generator = this.language.CreateCodeGenerator();
            StringBuilder sb = new StringBuilder();
            using (var stringWriter = new StringWriter(sb, CultureInfo.InvariantCulture))
            {
                var options = new SafeCodeGeneratorOptions()
                {
                    BracingStyle = "C",
                    IndentString = "    ",
                };

                generator.GenerateCodeFromCompileUnit(codeUnit, stringWriter, options);
            }

            return sb.ToString();
        }