https://github.com/heartacker/cscripting
write c# script like python
https://github.com/heartacker/cscripting
cs-script csharp-script csharp-sourcegenerator dotnet-interactive dotnet-script jupyter notebook polygon python pythonnet
Last synced: 2 months ago
JSON representation
write c# script like python
- Host: GitHub
- URL: https://github.com/heartacker/cscripting
- Owner: heartacker
- Created: 2023-05-11T15:42:36.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-28T06:30:24.000Z (about 1 year ago)
- Last Synced: 2025-03-28T22:51:11.277Z (3 months ago)
- Topics: cs-script, csharp-script, csharp-sourcegenerator, dotnet-interactive, dotnet-script, jupyter, notebook, polygon, python, pythonnet
- Language: C#
- Homepage: https://www.nuget.org/packages/CScripting
- Size: 112 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# 1. CScripting

[](https://github.com/heartacker/CScripting)
[](https://www.nuget.org/packages/CScripting)

[](https://github.com/heartacker/CScripting/releases)- [Roslyn](https://learn.microsoft.com/zh-cn/dotnet/api/?view=roslyn-dotnet-4.3.0)
- [CSharpScript](https://blog.51cto.com/u_13267193/5552052)
- [CSharpScript MemoryManager](https://blog.51cto.com/ineuos/4027860)
- [Unity引擎与C#脚本](https://blog.51cto.com/u_15127597/4740392)
- [Scripting-API-Samples](https://github.com/dotnet/roslyn/blob/main/docs/wiki/Scripting-API-Samples.md)- [1. CScripting](#1-cscripting)
- [1.1. Instruction](#11-instruction)
- [1.2. Recent Changelog](#12-recent-changelog)
- [1.3. Demo](#13-demo)
- [1.4. Dotnet script and repl](#14-dotnet-script-and-repl)
- [1.5. Extended function list](#15-extended-function-list)
- [1.6. Extended function list like `Matlab`](#16-extended-function-list-like-matlab)
- [1.7. `Python` Built-in function list](#17-python-built-in-function-list)## 1.1. Instruction
**write c# script like python**
!!! tip 思路
我们主要是想在 `C#` 实现 **`Python` 的内置函数**,并**在`C#` 中可以直接使用**, 以便提高简单脚本的编写效率。!!! tip 欢迎 ❤️
欢迎 任何 PR!!! tip idea
We aim to implement the **built-in function of python in `C#`** and **direct use in `C#`** to improve the effect.!!! tip **Welcome** ❤️
welcome any pull request## 1.2. Recent Changelog
- time: 2023年5月15日
- version: 1.0.6
- log:
1. change readme
2. add `help` function
3. add `dir` function
4. fix trim `print()` last sepmore information, see [CHANGELOG.md](https://github.com/heartacker/CScripting/blob/master/CHANGELOG.md)
## 1.3. Demo
- `Code`
🔗 [**C#**](./CScripting.Demo.csx)
```csharp
#r "nuget: CScripting, *"
using static CScripting;var addr = 0x12345678;
var addrr = hex(addr);print(addr); // 305419896
print(addrr);var val = 0x12345678;
var valr = bin(addr);print(val); // 305419896
print(valr);var c = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };
print(c);
print(c, sep:"\t");```
🔗 [**Python**](./CScripting.Compare.py)
```python
#r "nuget: CScripting, *"addr = 0x12345678
addrr = hex(addr)print(addr) # 305419896
print(addrr)val = 0x12345678
valr = bin(addr)print(val); # 305419896
print(valr)c = [0, 1, 2, 3, 4, 5, 6, 7]
print(c)
print(c, sep="\t")```
- `Output`
**C#**
```csharp
305419896
0x12345678
305419896
0b10010001101000101011001111000
{ 0, 1, 2, 3, 4, 5, 6, 7}
0 1 2 3 4 5 6 7```
**Python**
```python
305419896
0x12345678
305419896
0b10010001101000101011001111000
[0, 1, 2, 3, 4, 5, 6, 7]
[0, 1, 2, 3, 4, 5, 6, 7]```
## 1.4. [Dotnet script and repl](https://github.com/dotnet-script/dotnet-script#repl)
```shell
~$ dotnet-script
> #r "nuget: CScripting, *"
> using static CScripting;
> hex(1024)
"0x400"
> print("Hello CScripting")
Hello CScripting```
## 1.5. Extended function list
- MyOwn
- [ ] `load()`
- [ ] `unload()`## 1.6. Extended function list like `Matlab`
- coming
- [ ] `???`
- [ ] `????`## 1.7. `Python` Built-in function list
- A
- [x] [`abs()`](./CScripting/Built-in/abs.cs)
- [ ] `aiter()`
- [x] [`all()`](./CScripting/Built-in/all.cs)
- [x] [`any()`](./CScripting/Built-in/any.cs)
- [ ] `anext()`
- [ ] `ascii()`- B
- [x] [`bin()`](./CScripting/Built-in/bin.cs)
- [ ] `bool()`
- [ ] `breakpoint()`
- [x] [`bytearray()`](./CScripting/Built-in/bytearry.cs)
- [x] [`bytes()`](./CScripting/Built-in/bytearry.cs)- C
- [ ] `callable()`
- [x] [`chr()`](./CScripting/Built-in/chr.cs)
- [ ] `classmethod()`
- [ ] `compile()` **
- [ ] `complex()` **- D
- [ ] `delattr()`
- [ ] `dict()`
- [ ] `dir()` *
- [ ] `divmod()`- E
- [ ] `enumerate()`
- [ ] `eval()`
- [ ] `exec()`- F
- [ ] `filter()`
- [ ] `float()`
- [ ] `format()`
- [ ] `frozenset()`- G
- [ ] `getattr()`
- [ ] `globals()`- H
- [ ] `hasattr()`
- [ ] `hash()`
- [x] [`help()`](./CScripting/Built-in/help.cs)
- [x] [`hex()`](./CScripting/Built-in/hex.cs)- I
- [ ] `id()`
- [ ] `input()`
- [ ] `int()`
- [ ] `isinstance()`
- [ ] `issubclass()`
- [ ] `iter()`- L
- [ ] `len()`
- [ ] `list()`
- [ ] `locals()`- M
- [ ] `map()`
- [ ] `max()`
- [ ] `memoryview()`
- [ ] `min()`- N
- [ ] `next()`- O
- [ ] `object()`
- [x] [`oct()`](./CScripting/Built-in/oct.cs)
- [ ] `open()`
- [x] [`ord()`](./CScripting/Built-in/ord.cs)- P
- [ ] `pow()`
- [x] [`print()`](./CScripting/Built-in/print.cs)
- [ ] `property()`- R
- [ ] `range()`
- [ ] `repr()`
- [ ] `reversed()`
- [ ] `round()`- S
- [ ] `set()`
- [ ] `setattr()`
- [ ] `slice()`
- [ ] `sorted()`
- [ ] `staticmethod()`
- [ ] `str()`
- [ ] `sum()`
- [ ] `super()`- T
- [ ] `tuple()`
- [ ] `type()`
-- V
- [ ]`vars()`- Z
- [ ] `zip()`- misc
- [ ] `_`
- [ ] `__import__()`
- [ ] `???`