Coaster 0.1.6
See the version list below for details.
dotnet add package Coaster --version 0.1.6
NuGet\Install-Package Coaster -Version 0.1.6
<PackageReference Include="Coaster" Version="0.1.6" />
paket add Coaster --version 0.1.6
#r "nuget: Coaster, 0.1.6"
// Install Coaster as a Cake Addin #addin nuget:?package=Coaster&version=0.1.6 // Install Coaster as a Cake Tool #tool nuget:?package=Coaster&version=0.1.6
Coaster
The project Coaster is a library that allows easy parsing and formatting of C# source files. Coaster introduces a nice interface to manipulate C# source files, like adding fields, methods, attributes and so on.
Installation
dotnet add package Coaster
Usage
C# Parser API
Example:
Coast.Parse("public class HelloWorld {}");
C# Source Code Generation API
Coaster provides a nice API to generate C# classes. Here is an example:
var unit = new CUnit { Usings = { "System.Linq", "System", "System.IO" }, Members =
{
new CNamespace { Name = "Example", Members =
{
new CClass { Name = "Person", Members =
{
new CProperty { Type = "int", Name = "Id" },
new CProperty { Type = "string", Name = "FirstName" },
new CProperty { Type = "string", Name = "LastName" }
}
}
}
}
}
};
Console.WriteLine(unit.ToText());
This will produce:
using System;
using System.IO;
using System.Linq;
namespace Example
{
public class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
}
C# Source Code Modification API
Of course, it is possible to mix both approaches (parser and writer) to modify C# code programmatically:
var unit = Coast.Parse("public class SomeClass {}");
var clazz = unit.Members.Cast<CClass>().Single();
clazz.Members.Add(new CMethod { Name = "Main" });
Console.WriteLine(unit.ToText());
Formatting the C# Source Code
Coaster formats the C# Source Code by calling the Format()
method:
var humanCode = "public class MyClass{ private string field;}";
var formattedCode = Coast.Format(humanCode);
Console.WriteLine(formattedCode);
Building from sources
Just run dotnet pack
to build the sources.
Background info
This project uses the syntax tree parsing and writing of:
License
Everything is licensed according to this.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.8.1
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.8.0)
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.8.0)
-
net8.0
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.