Install
dotnet add package Meziantou.Framework.CodeDom --version 6.0.3
| Product | Versions |
|---|---|
| .NET |
README
Meziantou.Framework.CodeDom
Meziantou.Framework.CodeDom is a modern replacement for .NET CodeDom. The built-in CodeDom APIs have not evolved for years and do not support newer C# syntax, while this library lets you generate modern C# code using a strongly-typed object model.
Usage
The types are in the Meziantou.Framework.CodeDom namespace.
var unit = new CompilationUnit();
unit.AddUsing("System");
var ns = unit.AddNamespace("Demo");
var type = ns.AddType(new ClassDeclaration("Greeter")
{
Modifiers = Modifiers.Public,
});
var method = type.AddMember(new MethodDeclaration("GetMessage")
{
Modifiers = Modifiers.Public | Modifiers.Static,
ReturnType = typeof(string),
});
var nameArgument = method.AddArgument("name", typeof(string));
method.Statements = new ReturnStatement(Expression.Add("Hello ", nameArgument, "!"));
var generatedCode = unit.ToCsharpString();
generatedCode contains:
using System;
namespace Demo
{
public class Greeter
{
public static string GetMessage(string name)
{
return (("Hello " + name) + "!");
}
}
}
Changes from Previous Version
No structural changes between v6.0.2 and v6.0.3.
Adoption Assessment
A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.
Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.