Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ionite34/csgen
Framework for writing generated C# code
https://github.com/ionite34/csgen
Last synced: 8 days ago
JSON representation
Framework for writing generated C# code
- Host: GitHub
- URL: https://github.com/ionite34/csgen
- Owner: ionite34
- License: mit
- Created: 2024-02-07T18:42:28.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-04-29T15:30:27.000Z (8 months ago)
- Last Synced: 2024-11-27T22:15:48.445Z (25 days ago)
- Language: Python
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# csgen
[pypi]: https://pypi.org/project/csgen/
[![Build](https://github.com/ionite34/csgen/actions/workflows/build.yml/badge.svg)](https://github.com/ionite34/csgen/actions/workflows/build.yml)
[![PyPI](https://img.shields.io/pypi/v/csgen)][pypi]
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/csgen)][pypi]> Framework for writing generated C# code
## Example
- Usually you can inherit the `csgen.CSharpCodeGenerator` class to add your own helper methods for more specific code generation
```python
from csgen import CSharpCodeGenerator, ClassModifier, PropertyModifierwith open("Sample.g.cs", "w") as f:
gen = CSharpCodeGenerator(f)
gen.write_namespace("MyNamespace")
with gen.enter_class("Foo", ClassModifier.PUBLIC | ClassModifier.PARTIAL):
gen.write_comment("A comment")
gen.write_auto_property("Id", "int", PropertyModifier.PUBLIC | PropertyModifier.REQUIRED)
gen.write_auto_property("Name", "string", PropertyModifier.PROTECTED)
```Output File:
```csharp
//
#pragma warning disable
#nullable enablenamespace MyNamespace;
[global::System.CodeDom.Compiler.GeneratedCode("csgen", "1.0.0")]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public partial class MyClass
{
public required int Id { get; set; }
protected string Name { get; set; }
}
```