/// <summary> /// Converts an <see cref="OpenXmlPackage"/> into a <see cref="string"/> representation /// of dotnet source code that can be compiled to build <paramref name="pkg"/>. /// </summary> /// <param name="pkg"> /// The <see cref="OpenXmlPackage"/> object to generate source code for. /// </param> /// <param name="settings"> /// The <see cref="ISerializeSettings"/> to use during the code generation /// process. /// </param> /// <param name="provider"> /// The <see cref="CodeDomProvider"/> object to create the resulting source code. /// </param> /// <returns> /// A <see cref="string"/> representation of the source code generated by <paramref name="provider"/> /// that could create <paramref name="pkg"/> when compiled. /// </returns> public static string GenerateSourceCode(this OpenXmlPackage pkg, ISerializeSettings settings, CodeDomProvider provider) { var codeString = new System.Text.StringBuilder(); var code = pkg.GenerateSourceCode(settings); using (var sw = new StringWriter(codeString)) { provider.GenerateCodeFromCompileUnit(code, sw, new CodeGeneratorOptions() { BracingStyle = "C" }); } return codeString.ToString().RemoveOutputHeaders().Trim(); }
/// <summary> /// Converts an <see cref="OpenXmlPackage"/> into a CodeDom object that can be used /// to build code in a given .NET language to build the referenced <paramref name="pkg"/>. /// </summary> /// <param name="pkg"> /// The <see cref="OpenXmlPackage"/> object to generate source code for. /// </param> /// <param name="opts"> /// The <see cref="NamespaceAliasOptions"/> to apply to the resulting source code. /// </param> /// <returns> /// A new <see cref="CodeCompileUnit"/> containing the instructions to build /// the referenced <see cref="OpenXmlPackage"/>. /// </returns> public static CodeCompileUnit GenerateSourceCode(this OpenXmlPackage pkg, NamespaceAliasOptions opts) { return pkg.GenerateSourceCode(new DefaultSerializeSettings(opts)); }
/// <summary> /// Converts an <see cref="OpenXmlPackage"/> into a CodeDom object that can be used /// to build code in a given .NET language to build the referenced <paramref name="pkg"/>. /// </summary> /// <param name="pkg"> /// The <see cref="OpenXmlPackage"/> object to generate source code for. /// </param> /// <returns> /// A new <see cref="CodeCompileUnit"/> containing the instructions to build /// the referenced <see cref="OpenXmlPackage"/>. /// </returns> public static CodeCompileUnit GenerateSourceCode(this OpenXmlPackage pkg) { return pkg.GenerateSourceCode(new DefaultSerializeSettings()); }
/// <summary> /// Converts an <see cref="OpenXmlPackage"/> into a <see cref="string"/> representation /// of dotnet source code that can be compiled to build <paramref name="pkg"/>. /// </summary> /// <param name="pkg"> /// The <see cref="OpenXmlPackage"/> object to generate source code for. /// </param> /// <param name="opts"> /// The <see cref="NamespaceAliasOptions"/> to apply to the resulting source code. /// </param> /// <param name="provider"> /// The <see cref="CodeDomProvider"/> object to create the resulting source code. /// </param> /// <returns> /// A <see cref="string"/> representation of the source code generated by <paramref name="provider"/> /// that could create <paramref name="pkg"/> when compiled. /// </returns> public static string GenerateSourceCode(this OpenXmlPackage pkg, NamespaceAliasOptions opts, CodeDomProvider provider) { return pkg.GenerateSourceCode(new DefaultSerializeSettings(opts), provider); }
/// <summary> /// Converts an <see cref="OpenXmlPackage"/> into a <see cref="string"/> representation /// of dotnet source code that can be compiled to build <paramref name="pkg"/>. /// </summary> /// <param name="pkg"> /// The <see cref="OpenXmlPackage"/> object to generate source code for. /// </param> /// <param name="provider"> /// The <see cref="CodeDomProvider"/> object to create the resulting source code. /// </param> /// <returns> /// A <see cref="string"/> representation of the source code generated by <paramref name="provider"/> /// that could create <paramref name="pkg"/> when compiled. /// </returns> public static string GenerateSourceCode(this OpenXmlPackage pkg, CodeDomProvider provider) { return pkg.GenerateSourceCode(new DefaultSerializeSettings(), provider); }
/// <inheritdoc/> public override string BuildCodeDomTextDocument(CodeDomProvider provider) { return(_package.GenerateSourceCode(provider)); }