https://github.com/hexarc-software/csharp-dom
Microsoft C# source code generation based on the language document object model
https://github.com/hexarc-software/csharp-dom
code csharp generation nodejs typescript
Last synced: 2 months ago
JSON representation
Microsoft C# source code generation based on the language document object model
- Host: GitHub
- URL: https://github.com/hexarc-software/csharp-dom
- Owner: hexarc-software
- License: mit
- Created: 2020-09-19T17:45:17.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-28T16:53:02.000Z (over 4 years ago)
- Last Synced: 2025-03-12T19:38:29.530Z (2 months ago)
- Topics: code, csharp, generation, nodejs, typescript
- Language: TypeScript
- Homepage: https://github.com/hexarc-software/csharp-dom
- Size: 91.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
Microsoft C# source code generation based on the language document object model
======================================================[](https://www.npmjs.org/package/@hexarc/csharp-dom)
[](http://badges.mit-license.org)
[](https://npmjs.org/package/@hexarc/csharp-dom)
[](https://npmjs.org/package/@hexarc/csharp-dom)Generate Microsoft C# source files from any Node.js projects just using a simple and well-structured language document object model API.
This package is designed for usage with TypeScript and provides extensive typings for the C# document object model.
# Setup
Install with npm:```sh
npm install @hexarc/csharp-dom
```Using with node.js (ES6 syntax):
```js
import * as CSharpDom from "@hexarc/csharp-dom";
```Or using the CommonJS module syntax:
```js
const CSharpDom = require("@hexarc/csharp-dom");
```# Examples
* [Generate a POCO class](#generate-a-poco-class)
* [Generate an enum](#generate-an-enum)## Generate a POCO class ##
```ts
import * as fs from "fs";
import * as CSharpDom from "@hexarc/csharp-dom";const codeUnit: Hexarc.CSharpDom.CodeUnit = {
name: "Point2D.cs",
namespaces: [{
path: ["Hexarc", "Geometry"],
types: [{
kind: "class",
access: "public",
modifier: "sealed",
name: "Point2D",
members: [{
kind: "property",
access: "public",
type: { namespace: "System", name: "Single" },
name: "X"
}, {
kind: "property",
access: "public",
type: { namespace: "System", name: "Single" },
name: "Y"
}]
}]
}]
};fs.writeFileSync(codeUnit.name, CSharpDom.emit(codeUnit));
``````cs
namespace Hexarc.Geometry
{
public sealed class Point2D
{
public System.Single X { get; set; }
public System.Single Y { get; set; }
}
}
```## Generate an enum ##
```ts
import * as fs from "fs";
import * as CSharpDom from "@hexarc/csharp-dom";const codeUnit: Hexarc.CSharpDom.CodeUnit = {
name: "enum.cs",
namespaces: [{
path: ["Hexarc", "Flags"],
types: [{
kind: "enum",
access: "public",
name: "Direction",
members: [{
name: "Up"
}, {
name: "Down"
}, {
name: "Left"
}, {
name: "Right"
}]
}]
}]
};fs.writeFileSync(codeUnit.name, CSharpDom.emit(codeUnit));
``````csharp
namespace Hexarc.Flags
{
public enum Direction
{
Up,
Down,
Left,
Right
}
}
```## License
[MIT](LICENSE)