# mono.csharp

> Talk C# to .NET using Node. (still under development)

Latest version **0.0.1-fg** (published 2016-07-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install mono.csharp
pnpm add mono.csharp
yarn add mono.csharp
bun add mono.csharp
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1-fg |
| Published | 2016-07-29 |
| First published | 2016-07-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jochem Stoel |
| Maintainers | jochemstoel |
| Keywords | csharp, c#, csharpscriptengine, mono |

## Links

- npm: https://www.npmjs.com/package/mono.csharp
- npm.io page: https://npm.io/package/mono.csharp

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 0.0.1-fg (latest) — 2016-07-29
- 0.0.1-e — 2016-07-29
- 0.0.1-d — 2016-07-28
- 0.0.1-c — 2016-07-28
- 0.0.1-b — 2016-07-28
- 0.0.1-a — 2016-07-28
- 0.0.1 — 2016-07-28

## README

# CSharpScriptEngine <small><i>0.0.1</i></small>
<b>JOI</b> Javascript Oriented Interoperability.


<img src="https://66.media.tumblr.com/d626f233acc2093f5cc111caf716e106/tumblr_ob1i8cSHSB1ru9jhqo2_1280.jpg">

<i>This module requires .NET 4.0 or higher. It works by starting my C# Evaluator based on Mono.CSharp from the Mono Runtime. Node will start a child REPL process. You send C# code by writing to the child's stdin and subscribe to its stdout. </i>

## Minimal
Minimal use. Define a string in C# environment.

```javascript
const CSharpScriptEngine = require('mono.csharp')

let CSE = new CSharpScriptEngine()
CSE.on('data', data => {
	console.log(data)
})
CSE.write('string MyName = "Jochem Stoel";')
```

## Less Minimal
Load assemblies programatically and inhabit their namespace. 

```javascript
/* IPC using CSE */
let CSE = new CSharpScriptEngine()

/* handle however you feel */
function handle(data) {
	console.log(data)
}

/* sends "using $namespace" to process stdin */
CSE.using('System')
CSE.using('System.IO')
CSE.loadAssembly('MyFile.dll')
CSE.using('MyNamespace')

CSE.write('int x = 4;')

/* data is a console line */
CSE.on('data', data => {
	handle(data)
})

/* initiate dialog with user/client */
CSE.REPL()
```

## Methods

### Using(<small>namespace</small>)
using will simply prepend <a>"using "</a> before line and append <a>";"</a> after line before sending to stdin.  Basically CSE.using('System.IO') is the same as CSE.write('using System.IO;')

```javascript
/* can be written as chain */
CSE.using('System').using('System.IO').using('System.Reflection') ...

/* suggested way */
CSE.using('System.IO')
	.using('System.Windows.Forms')
	.loadAssembly('MyLibrary.dll')
	.using('MyNameSpace')
	.using('MyNameSpace.SubSpace')
	.write('var MyObj = new MyObject();')
.done()
```
### on(<small>what, that</small>)
wrap child_process.stdout.on to on()
### write(<small>line</small>)
write line to CSE process stdin
### REPL(<small>void</small>)
initiate REPL dialog with user/client
### done <small>nothing more to do</small>
kill the child
<img src="https://67.media.tumblr.com/a649cb2030c1a79cab9adb9990ffc449/tumblr_ob1i8cSHSB1ru9jhqo1_1280.jpg">

## Random technical details that could be useful
When CSE.exe evaluates an expression, it will stdout print "true" if it parsed correctly or "false" when you forget a semi colon or whatever. You can use this in your on.data event handler to determine what is happening.

If you want, you could prototype a method "getVar" that sends Console.WriteLine(varName.toString()) to the child process and then catch it with your handler function.

This package/module is experimental in general implementation as well as for myself. I strongly advise not to implement this in real world applications. However, if you do find a useful purpose for it or want to contribute, don't be shy and email me jochemstoel(@)gmail.com. That is after all why I publish these things in the first place.


<img src="http://33.media.tumblr.com/avatar_048a728a1488_128.png"><hr/>
# Jochem Stoel

Involuntary public figure.
<ul>
<li> https://www.npmjs.com/~jochemstoel</li>
<li> http://jochemstoel.github.io/</li>
<li> https://jochemstoel.tumblr.com/</li>
<li> https://jochemstoel.nl/</li>
<li> https://www.facebook.com/Jochem-Stoel-271292656217087/</li>
<li> https://www.quora.com/profile/Jochem-Stoel</li>
</ul>

---
_Source: https://npm.io/package/mono.csharp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
