From eae5837b75b601b03dcefec94052234d7399db7f Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 12 May 2023 07:48:07 +0800 Subject: [PATCH 01/74] abs --- Python.System/System.cs | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/Python.System/System.cs b/Python.System/System.cs index 741e71b..2705dd1 100644 --- a/Python.System/System.cs +++ b/Python.System/System.cs @@ -132,6 +132,8 @@ namespace Python /// public static class System { + #region abs + public static double Abs(Complex num) { return Abs(num.Magnitude); @@ -155,12 +157,30 @@ public static double Abs(PyObject num) [Obsolete("This method is deprecated, use `Abs` instead.")] public static double abs(Complex num) => Abs(num); - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] public static int abs(int num) => Math.Abs(num); + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] + public static long abs(long num) => Math.Abs(num); + + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] + public static short abs(short num) => Math.Abs(num); + + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] + public static sbyte abs(sbyte num) => Math.Abs(num); + + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] + public static double abs(double num) => Math.Abs(num); + + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] + public static decimal abs(decimal num) => Math.Abs(num); + + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] + public static float abs(float num) => Math.Abs(num); + #endregion + #region all /// /// /// @@ -181,8 +201,9 @@ public static bool All(IEnumerable iterable, Func(IEnumerable iterable, Func predicate = null) => All(iterable, predicate); + #endregion - + #region any /// /// /// @@ -203,8 +224,9 @@ public static bool Any(IEnumerable iterable, Func(IEnumerable iterable, Func predicate = null) => Any(iterable, predicate); + #endregion - + #region hex /// /// 将整形的数转为hex /// @@ -250,6 +272,10 @@ public static string Hex(ulong num, int? width = null) [Obsolete("This method is deprecated, use `{nameof(Hex)}` instead.")] public static string hex(ulong num, int? width = null) => Hex(num, width); + #endregion + + #region bin + /// /// 将整形的数转为二进制 /// @@ -281,6 +307,9 @@ public static string Bin(long num, int? width = null) [Obsolete("This method is deprecated, use `{nameof(bin)}` instead.")] public static string bin(long num, int? width = null) => Bin(num, width); + #endregion + + #region print [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] public static void print(object objects, @@ -325,6 +354,7 @@ public static void Print(IList objects, _file.Write(end); if (flush) _file.Flush(); } - } + #endregion + } } \ No newline at end of file From 9dd06c067703817b87bf5ee46bea6a21c993b96c Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 12 May 2023 07:48:21 +0800 Subject: [PATCH 02/74] fix namespace --- Python.System.Demo.dib | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Python.System.Demo.dib b/Python.System.Demo.dib index f039eb8..ab4f0d1 100644 --- a/Python.System.Demo.dib +++ b/Python.System.Demo.dib @@ -4,8 +4,8 @@ #!csharp -#r "nuget: S.System, *" -using static S.System; +#r "nuget: Python.System, *" +using static Python.System; #!csharp @@ -31,9 +31,9 @@ print(bin(value)); #!csharp -using static System.Math; +// #!csharp -var _12 = Abs(-12); +var _12 = abs(-12); print(_12); From 7ee33161201641ccbffb5609adec7a8fed4ce709 Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 12 May 2023 08:09:27 +0800 Subject: [PATCH 03/74] 1.0.2 --- Python.System.Demo.dib | 4 ++-- Python.System/Python.System.csproj | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Python.System.Demo.dib b/Python.System.Demo.dib index ab4f0d1..bbccb47 100644 --- a/Python.System.Demo.dib +++ b/Python.System.Demo.dib @@ -4,7 +4,7 @@ #!csharp -#r "nuget: Python.System, *" +#r "nuget: Python.System, 1.0.2" using static Python.System; #!csharp @@ -35,5 +35,5 @@ print(bin(value)); #!csharp -var _12 = abs(-12); +var _12 = abs(-15.6); print(_12); diff --git a/Python.System/Python.System.csproj b/Python.System/Python.System.csproj index 065fd52..2061e56 100644 --- a/Python.System/Python.System.csproj +++ b/Python.System/Python.System.csproj @@ -16,6 +16,8 @@ git static;python;function;script; 初始化版本。添加 hex,bin,print 函数 + 0.0.0.2 + 1.0.2 From 79372e6d01b6a84c878fe19b0000c91ddf02eee0 Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 12 May 2023 09:42:19 +0800 Subject: [PATCH 04/74] Create README.md --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..67ba129 --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +# Python.System + +![Nuget](https://img.shields.io/nuget/v/Python.System?style=for-the-badge) +![Nuget](https://img.shields.io/nuget/dt/Python.System?style=for-the-badge) + +write c# script like python +## demo +- code +```csharp +using static Python.System; + +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"); + +``` +- output +```log +305419896 +0x12345678 +305419896 +0b10010001101000101011001111000 +0 1 2 3 4 5 6 7 +0 1 2 3 4 5 6 7 + +``` From ffab35496137e2c54753478fa9da4a68074671f0 Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 12 May 2023 10:19:55 +0800 Subject: [PATCH 05/74] readme and vscode debug config --- .vscode/launch.json | 31 +++++++++++++++++++++++++++++++ Python.System.Demo.csx | 19 +++++++++++++++++++ Python.System.Demo.dib | 28 +++++++++++----------------- README.md | 17 +++++++++++++++-- omnisharp.json | 6 ++++++ 5 files changed, 82 insertions(+), 19 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 Python.System.Demo.csx create mode 100644 omnisharp.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..06624b2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,31 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Script Debug", + "type": "coreclr", + "request": "launch", + "program": "dotnet", + "args": [ + "exec", + // change to your own folder + "C:/Users/heartacker/.dotnet/tools/.store/dotnet-script/1.4.0/dotnet-script/1.4.0/tools/net7.0/any/dotnet-script.dll", + "${file}" + ], + "cwd": "${workspaceRoot}", + "stopAtEntry": false + }, + { + "name": ".NET Script Run", + "type": "coreclr", + "request": "launch", + "program": "dotnet", + "args": [ + "script", + "${file}" + ], + "cwd": "${workspaceRoot}", + "stopAtEntry": false + } + ] +} \ No newline at end of file diff --git a/Python.System.Demo.csx b/Python.System.Demo.csx new file mode 100644 index 0000000..19acfc9 --- /dev/null +++ b/Python.System.Demo.csx @@ -0,0 +1,19 @@ +#r "nuget: Python.System, 1.0.2" +using static Python.System; + +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"); diff --git a/Python.System.Demo.dib b/Python.System.Demo.dib index bbccb47..4291e8f 100644 --- a/Python.System.Demo.dib +++ b/Python.System.Demo.dib @@ -5,33 +5,27 @@ #!csharp #r "nuget: Python.System, 1.0.2" -using static Python.System; #!csharp -var abc = 10; -var efg = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; -print(abc); -print(efg); - -#!csharp +using static Python.System; var addr = 0x12345678; -var addrstr = hex(addr); -print(addrstr); -print(hex(addr)); +var addrr = hex(addr); -#!csharp +print(addr); // 305419896 +print(addrr); -var value = 0xa55a55aa; +var val = 0x12345678; +var valr = bin(addr); -var valuebin = bin(value); -print(valuebin); -print(bin(value)); +print(val); // 305419896 +print(valr); -#!csharp +var c = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }; -// +print(c); +print(c, sep:"\t"); #!csharp diff --git a/README.md b/README.md index 67ba129..b1d4e1d 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,13 @@ ![Nuget](https://img.shields.io/nuget/dt/Python.System?style=for-the-badge) write c# script like python -## demo +## [demo](./Python.System.Demo.csx) - code ```csharp using static Python.System; var addr = 0x12345678; -var addrr = Hex(addr); +var addrr = hex(addr); print(addr); // 305419896 print(addrr); @@ -37,3 +37,16 @@ print(c, sep:"\t"); 0 1 2 3 4 5 6 7 ``` + +## [dotnet script and repl](https://github.com/dotnet-script/dotnet-script#repl) + +```shell +~$ dotnet script +> #r "nuget: Python.System, 1.0.2" +> using static Python.System; +> hex(1024) +"0x400" +> print("Hello Scripy") +Hello Scripy + +``` \ No newline at end of file diff --git a/omnisharp.json b/omnisharp.json new file mode 100644 index 0000000..ff68708 --- /dev/null +++ b/omnisharp.json @@ -0,0 +1,6 @@ +{ + "script": { + "enableScriptNuGetReferences": true, + "defaultTargetFramework": "net7.0" + } +} \ No newline at end of file From c8bc60b246cee933f5ed536f67aadf006c111fce Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 12 May 2023 10:43:44 +0800 Subject: [PATCH 06/74] readme and demo --- Python.System.Compare.py | 17 +++++++++ README.md | 77 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 Python.System.Compare.py diff --git a/Python.System.Compare.py b/Python.System.Compare.py new file mode 100644 index 0000000..62b0f3c --- /dev/null +++ b/Python.System.Compare.py @@ -0,0 +1,17 @@ + +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") \ No newline at end of file diff --git a/README.md b/README.md index b1d4e1d..9605c6a 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,18 @@ ![Nuget](https://img.shields.io/nuget/dt/Python.System?style=for-the-badge) write c# script like python -## [demo](./Python.System.Demo.csx) +## demo - code + +
+ + + + + + +
+ +🔗 [ **C#** ](./Python.System.Demo.csx) + ```csharp +#r "nuget: Python.System, 1.0.2" using static Python.System; var addr = 0x12345678; @@ -27,8 +36,51 @@ print(c); print(c, sep:"\t"); ``` + + + +🔗 [ **Python** ](./Python.System.Compare.py) + +```python +#r + + +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 -```log + +
+ + + + + + +
+ +**C#** + +```csharp 305419896 0x12345678 305419896 @@ -38,6 +90,27 @@ print(c, sep:"\t"); ``` + + +**Python** + +```python +305419896 +0x12345678 +305419896 +0b10010001101000101011001111000 +[0, 1, 2, 3, 4, 5, 6, 7] +[0, 1, 2, 3, 4, 5, 6, 7] + +``` + +
+
+ ## [dotnet script and repl](https://github.com/dotnet-script/dotnet-script#repl) ```shell From 87bff2f4dcb10efc5c51730fce308bebfb22d8f8 Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 12 May 2023 11:19:27 +0800 Subject: [PATCH 07/74] update reme --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9605c6a..aed9e81 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,18 @@ # Python.System -![Nuget](https://img.shields.io/nuget/v/Python.System?style=for-the-badge) +[![GitHub stars](https://img.shields.io/github/stars/heartacker/Python.System?style=for-the-badge)](https://github.com/heartacker/Python.System) +[![Nuget](https://img.shields.io/nuget/v/Python.System?style=for-the-badge)](https://www.nuget.org/packages/Python.System) ![Nuget](https://img.shields.io/nuget/dt/Python.System?style=for-the-badge) +[![GitHub release](https://img.shields.io/github/v/release/heartacker/Python.System?style=for-the-badge)](https://github.com/heartacker/Python.System/releases) + +**write c# script like python** + +我们主要是想在 `C#` 实现 **`Python` 的内置函数**,并**在`C#` 中可以直接使用**, 以便提高简单脚本的编写效率。 + +We aim to implement the **built-in function of python in `C#`** and **direct use in `C#`** to improve the effect. -write c# script like python ## demo + - code
@@ -114,7 +122,7 @@ print(c, sep="\t") ## [dotnet script and repl](https://github.com/dotnet-script/dotnet-script#repl) ```shell -~$ dotnet script +~$ dotnet-script > #r "nuget: Python.System, 1.0.2" > using static Python.System; > hex(1024) From af76b96072941bd58d881f8ee32e01ae6d3a544c Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 12 May 2023 11:26:48 +0800 Subject: [PATCH 08/74] =?UTF-8?q?=E4=B8=8D=E8=AE=BE=E7=BD=AE=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Python.System.Compare.py | 2 ++ Python.System.Demo.csx | 2 +- Python.System.Demo.dib | 2 +- README.md | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Python.System.Compare.py b/Python.System.Compare.py index 62b0f3c..72071e2 100644 --- a/Python.System.Compare.py +++ b/Python.System.Compare.py @@ -1,3 +1,5 @@ +#r "nuget: Python.System, *" + addr = 0x12345678 addrr = hex(addr) diff --git a/Python.System.Demo.csx b/Python.System.Demo.csx index 19acfc9..8c6af67 100644 --- a/Python.System.Demo.csx +++ b/Python.System.Demo.csx @@ -1,4 +1,4 @@ -#r "nuget: Python.System, 1.0.2" +#r "nuget: Python.System, *" using static Python.System; var addr = 0x12345678; diff --git a/Python.System.Demo.dib b/Python.System.Demo.dib index 4291e8f..5006eb4 100644 --- a/Python.System.Demo.dib +++ b/Python.System.Demo.dib @@ -4,7 +4,7 @@ #!csharp -#r "nuget: Python.System, 1.0.2" +#r "nuget: Python.System, *" #!csharp diff --git a/README.md b/README.md index aed9e81..b2b9eec 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ We aim to implement the **built-in function of python in `C#`** and **direct use 🔗 [ **C#** ](./Python.System.Demo.csx) ```csharp -#r "nuget: Python.System, 1.0.2" +#r "nuget: Python.System, *" using static Python.System; var addr = 0x12345678; @@ -123,7 +123,7 @@ print(c, sep="\t") ```shell ~$ dotnet-script -> #r "nuget: Python.System, 1.0.2" +> #r "nuget: Python.System, *" > using static Python.System; > hex(1024) "0x400" From 50623edf65ea1a5d641aca8bd6c4aea8f075af47 Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 12 May 2023 11:48:47 +0800 Subject: [PATCH 09/74] =?UTF-8?q?=E8=BF=90=E8=A1=8C=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/tasks.json | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..b675f5b --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,21 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Run Current .NET Script", + "command": "dotnet", + "type": "shell", + "args": [ + "script", + "${file}" + ], + "group": "none", + "presentation": { + "reveal": "silent" + }, + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file From 2727d568f23db938269a4f0dc589547440c0af6c Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 12 May 2023 11:49:41 +0800 Subject: [PATCH 10/74] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20ObsoleteAttribute?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Python.System/ObsoleteAttr.cs | 18 ++++++++++++++++++ Python.System/System.cs | 6 ++++++ 2 files changed, 24 insertions(+) create mode 100644 Python.System/ObsoleteAttr.cs diff --git a/Python.System/ObsoleteAttr.cs b/Python.System/ObsoleteAttr.cs new file mode 100644 index 0000000..c9ec807 --- /dev/null +++ b/Python.System/ObsoleteAttr.cs @@ -0,0 +1,18 @@ +using System; + +namespace Python.Attr +{ + + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | + AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | + AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)] + internal sealed class ObsoleteAttribute : Attribute + { + public ObsoleteAttribute() { } + public ObsoleteAttribute(string message) { } + public ObsoleteAttribute(string message, bool error) { } + + public bool IsError { get; } + public string Message { get; } + } +} \ No newline at end of file diff --git a/Python.System/System.cs b/Python.System/System.cs index 2705dd1..28790a2 100644 --- a/Python.System/System.cs +++ b/Python.System/System.cs @@ -16,6 +16,12 @@ using static Python.Runtime.Py; using static Python.Runtime.PythonEngine; +#if false +using ObsoleteAttribute = System.ObsoleteAttribute; +#else +using ObsoleteAttribute = Python.Attr.ObsoleteAttribute; +#endif + namespace Python { /// From 993e8adbd5791e0813f4bed86ad1e1078bb90e71 Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 12 May 2023 11:50:15 +0800 Subject: [PATCH 11/74] nuget 103 --- Python.System/Python.System.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python.System/Python.System.csproj b/Python.System/Python.System.csproj index 2061e56..8bcc6c7 100644 --- a/Python.System/Python.System.csproj +++ b/Python.System/Python.System.csproj @@ -17,7 +17,7 @@ static;python;function;script; 初始化版本。添加 hex,bin,print 函数 0.0.0.2 - 1.0.2 + 1.0.3 From 3c633af6b4642a96139862254a7eeb5d809cd6c7 Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 12 May 2023 15:17:37 +0800 Subject: [PATCH 12/74] 104 --- Python.System/Python.System.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python.System/Python.System.csproj b/Python.System/Python.System.csproj index 8bcc6c7..852a9d4 100644 --- a/Python.System/Python.System.csproj +++ b/Python.System/Python.System.csproj @@ -17,7 +17,7 @@ static;python;function;script; 初始化版本。添加 hex,bin,print 函数 0.0.0.2 - 1.0.3 + 1.0.4 From ad0c129cb6b030e383e92a67a02a585e54f7774e Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 12 May 2023 15:21:45 +0800 Subject: [PATCH 13/74] use 3.0 --- Python.System/Python.System.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python.System/Python.System.csproj b/Python.System/Python.System.csproj index 852a9d4..5c0d7db 100644 --- a/Python.System/Python.System.csproj +++ b/Python.System/Python.System.csproj @@ -21,7 +21,7 @@ - + From b2680ef958da30be50589d3dfc461335960ab791 Mon Sep 17 00:00:00 2001 From: heartacker Date: Fri, 12 May 2023 16:19:17 +0800 Subject: [PATCH 14/74] =?UTF-8?q?=E4=B8=8D=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Python.System/Python.System.csproj | 2 +- Python.System/System.cs | 48 ++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Python.System/Python.System.csproj b/Python.System/Python.System.csproj index 5c0d7db..d47afcc 100644 --- a/Python.System/Python.System.csproj +++ b/Python.System/Python.System.csproj @@ -17,7 +17,7 @@ static;python;function;script; 初始化版本。添加 hex,bin,print 函数 0.0.0.2 - 1.0.4 + 1.0.5 diff --git a/Python.System/System.cs b/Python.System/System.cs index 28790a2..d3c3795 100644 --- a/Python.System/System.cs +++ b/Python.System/System.cs @@ -1,4 +1,5 @@ -using System; +#define OBSOLETE1 +using System; using System.Collections; using System.IO; using System.Linq; @@ -159,29 +160,37 @@ public static double Abs(PyObject num) } } - +#if OBSOLETE [Obsolete("This method is deprecated, use `Abs` instead.")] +#endif public static double abs(Complex num) => Abs(num); - +#if OBSOLETE [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif public static int abs(int num) => Math.Abs(num); - +#if OBSOLETE [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif public static long abs(long num) => Math.Abs(num); - +#if OBSOLETE [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif public static short abs(short num) => Math.Abs(num); - +#if OBSOLETE [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif public static sbyte abs(sbyte num) => Math.Abs(num); - +#if OBSOLETE [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif public static double abs(double num) => Math.Abs(num); - +#if OBSOLETE [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif public static decimal abs(decimal num) => Math.Abs(num); - +#if OBSOLETE [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif public static float abs(float num) => Math.Abs(num); #endregion @@ -202,8 +211,9 @@ public static bool All(IEnumerable iterable, Func(IEnumerable iterable, Func predicate = null) => All(iterable, predicate); @@ -225,8 +235,9 @@ public static bool Any(IEnumerable iterable, Func(IEnumerable iterable, Func predicate = null) => Any(iterable, predicate); @@ -251,8 +262,9 @@ public static string Hex(long num, int? width = null) return string.Format(format, num); } } - +#if OBSOLETE [Obsolete("This method is deprecated, use `{nameof(Hex)}` instead.")] +#endif public static string hex(long num, int? width = null) => Hex(num, width); /// @@ -274,8 +286,9 @@ public static string Hex(ulong num, int? width = null) return string.Format(format, num); } } - +#if OBSOLETE [Obsolete("This method is deprecated, use `{nameof(Hex)}` instead.")] +#endif public static string hex(ulong num, int? width = null) => Hex(num, width); #endregion @@ -309,15 +322,17 @@ public static string Bin(long num, int? width = null) return "0b" + format; } } - +#if OBSOLETE [Obsolete("This method is deprecated, use `{nameof(bin)}` instead.")] +#endif public static string bin(long num, int? width = null) => Bin(num, width); #endregion #region print - +#if OBSOLETE [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] +#endif public static void print(object objects, string sep = " ", string end = "\r\n", @@ -337,8 +352,9 @@ public static void Print(object objects, if (flush) _file.Flush(); } - +#if OBSOLETE [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] +#endif public static void print(IList objects, string sep = " ", string end = "\r\n", From 33e6e3e86cc1b43308e005c3770dd3205ce62f92 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 13 May 2023 14:37:05 +0800 Subject: [PATCH 15/74] abs --- Python.System/Python/abs.cs | 81 +++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Python.System/Python/abs.cs diff --git a/Python.System/Python/abs.cs b/Python.System/Python/abs.cs new file mode 100644 index 0000000..024ea61 --- /dev/null +++ b/Python.System/Python/abs.cs @@ -0,0 +1,81 @@ +using System; +using System.Numerics; + +namespace Python +{ + public static partial class System + { + #region abs + public const double e = Math.E; + public const double pi = Math.PI; + + /// + /// 将复数转为绝对值 + /// + /// + /// + public static double Abs(Complex num) => Math.Abs(num.Magnitude); + + /// + public static decimal Abs(decimal value) => Math.Abs(value); + + /// + public static double Abs(double value) => Math.Abs(value); + + /// + public static short Abs(short value) => Math.Abs(value); + + /// + public static int Abs(int value) => Math.Abs(value); + + /// + public static long Abs(long value) => Math.Abs(value); + + /// + public static sbyte Abs(sbyte value) => Math.Abs(value); + + /// + public static float Abs(float value) => Math.Abs(value); + +#if OBSOLETE + [Obsolete("This method is deprecated, use `Abs` instead.")] +#endif + public static double abs(Complex num) => Math.Abs(num.Magnitude); + +#if OBSOLETE + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif + public static double abs(double num) => Math.Abs(num); + +#if OBSOLETE + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif + public static decimal abs(decimal num) => Math.Abs(num); + +#if OBSOLETE + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif + public static short abs(short num) => Math.Abs(num); + +#if OBSOLETE + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif + public static int abs(int num) => Math.Abs(num); +#if OBSOLETE + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif + public static long abs(long num) => Math.Abs(num); +#if OBSOLETE + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif + public static sbyte abs(sbyte num) => Math.Abs(num); + +#if OBSOLETE + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif + public static float abs(float num) => Math.Abs(num); + + #endregion + + } +} From 2731d6bc4bbb4885ad57f83350b0fb618690f7e1 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 13 May 2023 15:38:28 +0800 Subject: [PATCH 16/74] byte and bytesarray --- Python.System/Python/bytes.cs | 78 +++++++++++ Python.System/System.cs | 251 +--------------------------------- 2 files changed, 81 insertions(+), 248 deletions(-) create mode 100644 Python.System/Python/bytes.cs diff --git a/Python.System/Python/bytes.cs b/Python.System/Python/bytes.cs new file mode 100644 index 0000000..7617085 --- /dev/null +++ b/Python.System/Python/bytes.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; + +namespace Python +{ + public static partial class System + { + #region bytes + + public static byte[] bytes(string source, string encoding = "utf-8", string errors = "strict") + => bytearray(source, encoding, errors); + /// + /// 仅支持byte sbyte int uint ushort short 数组 + /// + /// + /// + public static byte[] bytes(IEnumerable source) => bytearray(source); + public static byte[] bytes(uint source) => bytearray(source); + public static byte[] bytes(int source) => bytearray(source); + + + public static byte[] bytearray(string source, string encoding = "utf-8", string errors = "strict") + { + return Encoding.GetEncoding(encoding, new EncoderExceptionFallback(), new DecoderExceptionFallback()).GetBytes(source); + } + + public static byte[] bytearray(uint source) => new byte[source]; + public static byte[] bytearray(int source) => bytearray((uint)source); + + /// + /// 仅支持byte sbyte int uint ushort short 数组 + /// + /// + /// + /// + public static byte[] bytearray(IEnumerable source) + { + if (source is IEnumerable bytei) + { + byte[] byteArray = bytei.ToArray(); + return byteArray; + } + else if (source is IEnumerable sbytei) + { + byte[] byteArray = sbytei.Select(i => (byte)i).ToArray(); + return byteArray; + } + else if (source is IEnumerable shorti) + { + byte[] byteArray = shorti.Select(i => (byte)i).ToArray(); + return byteArray; + } + else if (source is IEnumerable ushorti) + { + byte[] byteArray = ushorti.Select(i => (byte)i).ToArray(); + return byteArray; + } + else if (source is IEnumerable inti) + { + byte[] byteArray = inti.Select(i => (byte)i).ToArray(); + return byteArray; + } + else if (source is IEnumerable uinti) + { + byte[] byteArray = uinti.Select(i => (byte)i).ToArray(); + return byteArray; + } + else + { + throw new ArgumentException("source parameter must be an integer, a string, or an iterable object of integers or bytes"); + } + } + #endregion + } +} diff --git a/Python.System/System.cs b/Python.System/System.cs index d3c3795..9c43a55 100644 --- a/Python.System/System.cs +++ b/Python.System/System.cs @@ -1,5 +1,4 @@ -#define OBSOLETE1 -using System; +using System; using System.Collections; using System.IO; using System.Linq; @@ -12,11 +11,6 @@ using static System.Numerics.Complex; using static System.Numerics.BigInteger; -using Python.Runtime; -using static Python.Runtime.Runtime; -using static Python.Runtime.Py; -using static Python.Runtime.PythonEngine; - #if false using ObsoleteAttribute = System.ObsoleteAttribute; #else @@ -28,7 +22,7 @@ namespace Python /// /// A: /// abs() - /// aiter() + /// aiter() // x /// all() /// any() /// anext() @@ -137,246 +131,7 @@ namespace Python /// _ /// __import__() /// - public static class System + public static partial class System { - #region abs - - public static double Abs(Complex num) - { - return Abs(num.Magnitude); - } - - /// - /// 仅支持复数类型 - /// - /// - /// - public static double Abs(PyObject num) - { - using (GIL()) - { - var c = num.As(); - return Abs(c.Magnitude); - } - } - -#if OBSOLETE - [Obsolete("This method is deprecated, use `Abs` instead.")] -#endif - public static double abs(Complex num) => Abs(num); -#if OBSOLETE - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] -#endif - public static int abs(int num) => Math.Abs(num); -#if OBSOLETE - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] -#endif - public static long abs(long num) => Math.Abs(num); -#if OBSOLETE - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] -#endif - public static short abs(short num) => Math.Abs(num); -#if OBSOLETE - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] -#endif - public static sbyte abs(sbyte num) => Math.Abs(num); -#if OBSOLETE - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] -#endif - public static double abs(double num) => Math.Abs(num); -#if OBSOLETE - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] -#endif - public static decimal abs(decimal num) => Math.Abs(num); -#if OBSOLETE - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] -#endif - public static float abs(float num) => Math.Abs(num); - - #endregion - - #region all - /// - /// - /// - /// - /// - /// - /// - public static bool All(IEnumerable iterable, Func predicate = null) - { - if (predicate == null) - return iterable.All(a => Convert.ToBoolean(a)); - else - return iterable.All(predicate); - } - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(All)}` instead.")] -#endif - public static bool all(IEnumerable iterable, Func predicate = null) - => All(iterable, predicate); - - #endregion - - #region any - /// - /// - /// - /// - /// - /// - /// - public static bool Any(IEnumerable iterable, Func predicate = null) - { - if (predicate == null) - return iterable.Any(); - else - return iterable.Any(predicate); - } - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Any)}` instead.")] -#endif - public static bool any(IEnumerable iterable, Func predicate = null) - => Any(iterable, predicate); - - #endregion - - #region hex - /// - /// 将整形的数转为hex - /// - /// 整数 - /// 位宽, 则不关注,如果转换结果大于位宽,则取位宽 - /// hex字符串 - public static string Hex(long num, int? width = null) - { - if (width == null || width <= 0) - { - return string.Format("0x{0:X}", num); - } - else - { - string format = "0x{0:" + "X" + width + "}"; - return string.Format(format, num); - } - } -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Hex)}` instead.")] -#endif - public static string hex(long num, int? width = null) => Hex(num, width); - - /// - /// 将ulong整形的数转为hex - /// - /// 整数 - /// 位宽, 则不关注,如果转换结果大于位宽,则取位宽 - /// hex字符串 - - public static string Hex(ulong num, int? width = null) - { - if (width == null || width <= 0) - { - return string.Format("0x{0:X}", num); - } - else - { - string format = "0x{0:" + "X" + width + "}"; - return string.Format(format, num); - } - } -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Hex)}` instead.")] -#endif - public static string hex(ulong num, int? width = null) => Hex(num, width); - - #endregion - - #region bin - - /// - /// 将整形的数转为二进制 - /// - /// 整数 - /// 位宽, 则不关注,如果转换结果大于位宽,则取位宽 - /// 二进制字符串 - public static string Bin(long num, int? width = null) - { - if (width == null || width <= 0) - { - return "0b" + Convert.ToString(num, 2); - } - else - { - string format = Convert.ToString(num, 2); - if (format.Length < width) - { - string par = ""; - for (int c = 0; c < width - format.Length; c++) - { - par += "0"; - } - return "0b" + par + format; - } - return "0b" + format; - } - } -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(bin)}` instead.")] -#endif - public static string bin(long num, int? width = null) => Bin(num, width); - - #endregion - - #region print -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] -#endif - public static void print(object objects, - string sep = " ", - string end = "\r\n", - StreamWriter file = null, - bool flush = false) => Print(objects, sep, end, file, flush); - - public static void Print(object objects, - string sep = " ", - string end = "\r\n", - StreamWriter file = null, - bool flush = false) - { - var _file = file ?? Console.Out; - - _file.Write(objects.ToString()); - _file.Write(end); - if (flush) _file.Flush(); - } - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] -#endif - public static void print(IList objects, - string sep = " ", - string end = "\r\n", - StreamWriter file = null, - bool flush = false) => Print(objects, sep, end, file, flush); - - public static void Print(IList objects, - string sep = " ", - string end = "\r\n", - StreamWriter file = null, - bool flush = false) - { - var _file = file ?? Console.Out; - foreach (var item in objects) - { - _file.Write(item.ToString()); - _file.Write(sep); - } - _file.Write(end); - if (flush) _file.Flush(); - } - #endregion - } } \ No newline at end of file From b1053e6b61049276c64f1aa66da026f0cd3cc068 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 13 May 2023 15:58:38 +0800 Subject: [PATCH 17/74] ABS --- Python.System/Python/abs.cs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Python.System/Python/abs.cs b/Python.System/Python/abs.cs index 024ea61..f9aca8e 100644 --- a/Python.System/Python/abs.cs +++ b/Python.System/Python/abs.cs @@ -14,28 +14,34 @@ public static partial class System /// /// /// - public static double Abs(Complex num) => Math.Abs(num.Magnitude); + public static double Abs(Complex num) => Abs(num.Magnitude); /// - public static decimal Abs(decimal value) => Math.Abs(value); + public static decimal Abs(decimal value) => Abs(value); /// - public static double Abs(double value) => Math.Abs(value); + public static double Abs(double value) => Abs(value); /// - public static short Abs(short value) => Math.Abs(value); + public static short Abs(short value) => Abs(value); /// - public static int Abs(int value) => Math.Abs(value); + public static int Abs(int value) => Abs(value); /// - public static long Abs(long value) => Math.Abs(value); + public static long Abs(long value) => Abs(value); /// - public static sbyte Abs(sbyte value) => Math.Abs(value); + public static sbyte Abs(sbyte value) => Abs(value); /// - public static float Abs(float value) => Math.Abs(value); + public static float Abs(float value) => Abs(value); + + + + + + #if OBSOLETE [Obsolete("This method is deprecated, use `Abs` instead.")] From a921c85f9fb3b8af6d2833a28032963160886123 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 13 May 2023 15:58:43 +0800 Subject: [PATCH 18/74] ALL --- Python.System/Python/all.cs | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Python.System/Python/all.cs diff --git a/Python.System/Python/all.cs b/Python.System/Python/all.cs new file mode 100644 index 0000000..e00ee8f --- /dev/null +++ b/Python.System/Python/all.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; + +namespace Python +{ + public static partial class System + { + #region all + /// + /// + /// + /// + /// + /// + /// + public static bool All(IEnumerable iterable, Func predicate = null) + => All(iterable, predicate); + + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(All)}` instead.")] +#endif + public static bool all(IEnumerable iterable, Func predicate = null) + { + if (predicate == null) + return iterable.All(a => Convert.ToBoolean(a)); + else + return iterable.All(predicate); + } + + + #endregion + + } +} From c12cf1b32b301081d35829e93f6f491f3305a9c7 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 13 May 2023 15:58:54 +0800 Subject: [PATCH 19/74] bin --- Python.System/Python/any.cs | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Python.System/Python/any.cs diff --git a/Python.System/Python/any.cs b/Python.System/Python/any.cs new file mode 100644 index 0000000..a787def --- /dev/null +++ b/Python.System/Python/any.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; + +namespace Python +{ + public static partial class System + { + #region any + /// + /// + /// + /// + /// + /// + /// + public static bool Any(IEnumerable iterable, Func predicate = null) + => Any(iterable, predicate); + + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Any)}` instead.")] +#endif + public static bool any(IEnumerable iterable, Func predicate = null) + { + if (predicate == null) + return iterable.Any(); + else + return iterable.Any(predicate); + } + + #endregion + + } +} From 71fa1b65ea088d3845775ad87390221b9aa5bbb3 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 13 May 2023 15:59:06 +0800 Subject: [PATCH 20/74] bin --- Python.System/Python/bin.cs | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Python.System/Python/bin.cs diff --git a/Python.System/Python/bin.cs b/Python.System/Python/bin.cs new file mode 100644 index 0000000..29ca9b8 --- /dev/null +++ b/Python.System/Python/bin.cs @@ -0,0 +1,50 @@ +using System; +using System.Numerics; + +namespace Python +{ + public static partial class System + { + #region bin + + /// + /// 将整形的数转为二进制 + /// + /// 整数 + /// 位宽, 则不关注,如果转换结果大于位宽,则取位宽 + /// 二进制字符串 + public static string Bin(long x, int? width = null) + => Bin(x, width); + + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(bin)}` instead.")] +#endif + public static string bin(long x, int? width = null) + { + if (width == null || width <= 0) + { + return "0b" + Convert.ToString(x, 2); + } + else + { + string format = Convert.ToString(x, 2); + if (format.Length < width) + { + string par = ""; + for (int c = 0; c < width - format.Length; c++) + { + par += "0"; + } + return "0b" + par + format; + } + return "0b" + format; + } + } + + #endregion + } +} From 77afa3d6a7fbc7b69009925bd8d1e107beec5dbe Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 13 May 2023 15:59:15 +0800 Subject: [PATCH 21/74] bytes --- .../Python/{bytes.cs => bytearry.cs} | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) rename Python.System/Python/{bytes.cs => bytearry.cs} (69%) diff --git a/Python.System/Python/bytes.cs b/Python.System/Python/bytearry.cs similarity index 69% rename from Python.System/Python/bytes.cs rename to Python.System/Python/bytearry.cs index 7617085..c38f595 100644 --- a/Python.System/Python/bytes.cs +++ b/Python.System/Python/bytearry.cs @@ -10,6 +10,23 @@ public static partial class System { #region bytes + + public static byte[] Bytes(string source, string encoding = "utf-8", string errors = "strict") + => bytes(source, encoding, errors); + /// + /// 仅支持byte sbyte int uint ushort short 数组 + /// + /// + /// + public static byte[] Bytes(IEnumerable source) => bytes(source); + public static byte[] Bytes(uint source) => bytes(source); + public static byte[] Bytes(int source) => bytes(source); + + + + + + public static byte[] bytes(string source, string encoding = "utf-8", string errors = "strict") => bytearray(source, encoding, errors); /// @@ -22,6 +39,32 @@ public static byte[] bytes(string source, string encoding = "utf-8", string erro public static byte[] bytes(int source) => bytearray(source); + + #endregion + + + #region bytearry + + + public static byte[] Bytearray(string source, string encoding = "utf-8", string errors = "strict") + => bytearray(source, encoding, errors); + + public static byte[] Bytearray(uint source) => bytearray(source); + public static byte[] Bytearray(int source) => bytearray((uint)source); + + /// + /// 仅支持byte sbyte int uint ushort short 数组 + /// + /// + /// + /// + public static byte[] Bytearray(IEnumerable source) => bytearray(source); + + + + + + public static byte[] bytearray(string source, string encoding = "utf-8", string errors = "strict") { return Encoding.GetEncoding(encoding, new EncoderExceptionFallback(), new DecoderExceptionFallback()).GetBytes(source); From 9bf3cce9eb8b233647a7458cbf860c6f045ecd62 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 13 May 2023 15:59:35 +0800 Subject: [PATCH 22/74] hex --- Python.System/Python/hex.cs | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Python.System/Python/hex.cs diff --git a/Python.System/Python/hex.cs b/Python.System/Python/hex.cs new file mode 100644 index 0000000..5f992ae --- /dev/null +++ b/Python.System/Python/hex.cs @@ -0,0 +1,68 @@ +using System; +using System.Numerics; + +namespace Python +{ + public static partial class System + { + #region hex + /// + /// 将整形的数转为hex + /// + /// 整数 + /// 位宽, 则不关注,如果转换结果大于位宽,则取位宽 + /// hex字符串 + public static string Hex(long x, int? width = null) + => Hex(x, width); + + /// + /// 将ulong整形的数转为hex + /// + /// 整数 + /// 位宽, 则不关注,如果转换结果大于位宽,则取位宽 + /// hex字符串 + + public static string Hex(ulong x, int? width = null) + => Hex(x, width); + + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Hex)}` instead.")] +#endif + public static string hex(long x, int? width = null) + { + if (width == null || width <= 0) + { + return string.Format("0x{0:X}", x); + } + else + { + string format = "0x{0:" + "X" + width + "}"; + return string.Format(format, x); + } + } + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Hex)}` instead.")] +#endif + public static string hex(ulong x, int? width = null) + { + if (width == null || width <= 0) + { + return string.Format("0x{0:X}", x); + } + else + { + string format = "0x{0:" + "X" + width + "}"; + return string.Format(format, x); + } + } + + #endregion + + } +} From c5a8d8ddc1d159129d34b083405597424a696422 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 13 May 2023 15:59:40 +0800 Subject: [PATCH 23/74] hex --- Python.System/Python/print.cs | 66 +++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Python.System/Python/print.cs diff --git a/Python.System/Python/print.cs b/Python.System/Python/print.cs new file mode 100644 index 0000000..4e08b25 --- /dev/null +++ b/Python.System/Python/print.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections; +using System.IO; +using System.Numerics; + +namespace Python +{ + public static partial class System + { + #region print + + public static void Print(object @object, + string sep = " ", + string end = "\r\n", + StreamWriter file = null, + bool flush = false) => print(@object, sep, end, file, flush); + + + public static void Print(IList @object, + string sep = " ", + string end = "\r\n", + StreamWriter file = null, + bool flush = false) => print(@object, sep, end, file, flush); + + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] +#endif + public static void print(object @object, + string sep = " ", + string end = "\r\n", + StreamWriter file = null, + bool flush = false) + { + var _file = file ?? Console.Out; + + _file.Write(@object.ToString()); + _file.Write(end); + if (flush) _file.Flush(); + } + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] +#endif + public static void print(IList @object, + string sep = " ", + string end = "\r\n", + StreamWriter file = null, + bool flush = false) + { + var _file = file ?? Console.Out; + foreach (var item in @object) + { + _file.Write(item.ToString()); + _file.Write(sep); + } + _file.Write(end); + if (flush) _file.Flush(); + } + #endregion + + } +} From 5875834ac280908f229705bc9d4128595e562b55 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 13 May 2023 16:01:25 +0800 Subject: [PATCH 24/74] print obj --- Python.System/Python/print.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python.System/Python/print.cs b/Python.System/Python/print.cs index 4e08b25..7024725 100644 --- a/Python.System/Python/print.cs +++ b/Python.System/Python/print.cs @@ -37,7 +37,7 @@ public static void print(object @object, { var _file = file ?? Console.Out; - _file.Write(@object.ToString()); + _file.Write(@object); _file.Write(end); if (flush) _file.Flush(); } From 047b1e7feeac8aded64256b85d2b9ed2de9914de Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 13 May 2023 16:01:37 +0800 Subject: [PATCH 25/74] remove pythonnet --- Python.System/Python.System.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python.System/Python.System.csproj b/Python.System/Python.System.csproj index d47afcc..f5fae08 100644 --- a/Python.System/Python.System.csproj +++ b/Python.System/Python.System.csproj @@ -21,7 +21,7 @@ - + From 85111eb6b6995b4577c8c3918070a6e379800609 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 13 May 2023 16:11:16 +0800 Subject: [PATCH 26/74] Chr --- Python.System/Python/chr.cs | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Python.System/Python/chr.cs diff --git a/Python.System/Python/chr.cs b/Python.System/Python/chr.cs new file mode 100644 index 0000000..78cf64b --- /dev/null +++ b/Python.System/Python/chr.cs @@ -0,0 +1,60 @@ +using System; + +namespace Python +{ + public static partial class System + { + #region chr + public static string Chr(uint i) => chr(i); + + /// + /// 返回 Unicode 码位为整数 i 的字符的字符串格式。例如,chr(97) 返回字符串 'a',chr(8364) 返回字符串 '€'。这是 ord() 的逆函数。 + + /// 实参的合法范围是 0 到 1,114,111(16 进制表示是 0x10FFFF)。如果 i 超过这个范围,会触发 ValueError 异常。 + /// + /// + /// + /// + public static string Chr(int i) => chr(i); + + + + + + + + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Hex)}` instead.")] +#endif + public static string chr(uint i) => chr(i); + + + + /// + /// 返回 Unicode 码位为整数 i 的字符的字符串格式。例如,chr(97) 返回字符串 'a',chr(8364) 返回字符串 '€'。这是 ord() 的逆函数。 + + /// 实参的合法范围是 0 到 1,114,111(16 进制表示是 0x10FFFF)。如果 i 超过这个范围,会触发 ValueError 异常。 + /// + /// + /// + /// + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Hex)}` instead.")] +#endif + public static string chr(int i) + { + if (i < 0 || i > 0x10FFFF) + { + throw new ArgumentOutOfRangeException("i", "实参的合法范围是 0 到 1,114,111(16 进制表示是 0x10FFFF)"); + } + return Convert.ToChar(i).ToString(); + } + #endregion + + } +} From 5b99c92457ae751fc97f0dc413e51b40b5591a67 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 13 May 2023 16:17:38 +0800 Subject: [PATCH 27/74] ord --- Python.System/Python/ord.cs | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Python.System/Python/ord.cs diff --git a/Python.System/Python/ord.cs b/Python.System/Python/ord.cs new file mode 100644 index 0000000..bc8e4a1 --- /dev/null +++ b/Python.System/Python/ord.cs @@ -0,0 +1,52 @@ +using System; + +namespace Python +{ + public static partial class System + { + #region ord + + public static int Ord(char c) => ord(c); + + + + /// + /// 对表示单个 Unicode 字符的字符串,返回代表它 Unicode 码点的整数。例如 ord('a') 返回整数 97, ord('€') (欧元符号)返回 8364 。这是 chr() 的逆函数。 + /// + /// + /// + /// + public static int Ord(string c) => ord(c); + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Ord)}` instead.")] +#endif + public static int ord(char c) => Convert.ToInt32(c); + + + + /// + /// 对表示单个 Unicode 字符的字符串,返回代表它 Unicode 码点的整数。例如 ord('a') 返回整数 97, ord('€') (欧元符号)返回 8364 。这是 chr() 的逆函数。 + /// + /// + /// + /// + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Ord)}` instead.")] +#endif + public static int ord(string c) + { + if (string.IsNullOrEmpty(c) || c.Length != 1) + { + throw new ArgumentException("实参必须是表示单个 Unicode 字符的字符串"); + } + return Convert.ToInt32(c[0]); + } + #endregion + + } +} From ccb69392e7ee6d814f533ad5d097b2c3bc86183f Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 01:35:19 +0800 Subject: [PATCH 28/74] =?UTF-8?q?static=20=E5=8F=AA=E8=A6=81=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=AE=9A=E4=B9=89=E4=BA=86=E5=B0=B1=E5=A5=BD=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Python.System/Python/abs.cs | 4 ++-- Python.System/Python/all.cs | 2 +- Python.System/Python/any.cs | 2 +- Python.System/Python/bin.cs | 2 +- Python.System/Python/bytearry.cs | 2 +- Python.System/Python/chr.cs | 2 +- Python.System/Python/hex.cs | 2 +- Python.System/Python/ord.cs | 2 +- Python.System/Python/print.cs | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Python.System/Python/abs.cs b/Python.System/Python/abs.cs index f9aca8e..a1b7691 100644 --- a/Python.System/Python/abs.cs +++ b/Python.System/Python/abs.cs @@ -3,10 +3,10 @@ namespace Python { - public static partial class System + public partial class System { #region abs - public const double e = Math.E; + //public const double e = Math.E; public const double pi = Math.PI; /// diff --git a/Python.System/Python/all.cs b/Python.System/Python/all.cs index e00ee8f..90e4920 100644 --- a/Python.System/Python/all.cs +++ b/Python.System/Python/all.cs @@ -5,7 +5,7 @@ namespace Python { - public static partial class System + public partial class System { #region all /// diff --git a/Python.System/Python/any.cs b/Python.System/Python/any.cs index a787def..f6c533d 100644 --- a/Python.System/Python/any.cs +++ b/Python.System/Python/any.cs @@ -5,7 +5,7 @@ namespace Python { - public static partial class System + public partial class System { #region any /// diff --git a/Python.System/Python/bin.cs b/Python.System/Python/bin.cs index 29ca9b8..da897b6 100644 --- a/Python.System/Python/bin.cs +++ b/Python.System/Python/bin.cs @@ -3,7 +3,7 @@ namespace Python { - public static partial class System + public partial class System { #region bin diff --git a/Python.System/Python/bytearry.cs b/Python.System/Python/bytearry.cs index c38f595..94452fc 100644 --- a/Python.System/Python/bytearry.cs +++ b/Python.System/Python/bytearry.cs @@ -6,7 +6,7 @@ namespace Python { - public static partial class System + public partial class System { #region bytes diff --git a/Python.System/Python/chr.cs b/Python.System/Python/chr.cs index 78cf64b..9a8870f 100644 --- a/Python.System/Python/chr.cs +++ b/Python.System/Python/chr.cs @@ -2,7 +2,7 @@ namespace Python { - public static partial class System + public partial class System { #region chr public static string Chr(uint i) => chr(i); diff --git a/Python.System/Python/hex.cs b/Python.System/Python/hex.cs index 5f992ae..8ef4f39 100644 --- a/Python.System/Python/hex.cs +++ b/Python.System/Python/hex.cs @@ -3,7 +3,7 @@ namespace Python { - public static partial class System + public partial class System { #region hex /// diff --git a/Python.System/Python/ord.cs b/Python.System/Python/ord.cs index bc8e4a1..de6917e 100644 --- a/Python.System/Python/ord.cs +++ b/Python.System/Python/ord.cs @@ -2,7 +2,7 @@ namespace Python { - public static partial class System + public partial class System { #region ord diff --git a/Python.System/Python/print.cs b/Python.System/Python/print.cs index 7024725..ee6a451 100644 --- a/Python.System/Python/print.cs +++ b/Python.System/Python/print.cs @@ -5,7 +5,7 @@ namespace Python { - public static partial class System + public partial class System { #region print From d4cb52355ad8ae71e93556a9db4a58a7ea41d1a0 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 01:36:04 +0800 Subject: [PATCH 29/74] =?UTF-8?q?=E5=A4=8D=E7=94=A8=E4=B8=80=E4=BA=9Bpytho?= =?UTF-8?q?nnet=E7=9A=84=E4=BB=A3=E7=A0=81=E3=80=82=E9=9D=9E=E5=B8=B8?= =?UTF-8?q?=E6=84=9F=E8=B0=A2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://pythonnet.github.io --- Python.System/Runtime/ClassBase.cs | 39 ++ Python.System/Runtime/ClassHelper.cs | 565 +++++++++++++++++++ Python.System/Runtime/ExtensionType.cs | 85 +++ Python.System/Runtime/ManagedType.cs | 6 + Python.System/Runtime/OpsHelper.cs | 99 ++++ Python.System/Runtime/ReflectionPolyfills.cs | 39 ++ 6 files changed, 833 insertions(+) create mode 100644 Python.System/Runtime/ClassBase.cs create mode 100644 Python.System/Runtime/ClassHelper.cs create mode 100644 Python.System/Runtime/ExtensionType.cs create mode 100644 Python.System/Runtime/ManagedType.cs create mode 100644 Python.System/Runtime/OpsHelper.cs create mode 100644 Python.System/Runtime/ReflectionPolyfills.cs diff --git a/Python.System/Runtime/ClassBase.cs b/Python.System/Runtime/ClassBase.cs new file mode 100644 index 0000000..0ffb54f --- /dev/null +++ b/Python.System/Runtime/ClassBase.cs @@ -0,0 +1,39 @@ + +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace Python +{ + internal class ClassBase : ManagedType, IDeserializationCallback + { + internal List dotNetMembers = new List(); + // internal Indexer? indexer; + internal readonly Dictionary richcompare = new Dictionary(); + internal Type type; + + internal ClassBase(Type tp) + { + if (tp is null) throw new ArgumentNullException(nameof(type)); + + // indexer = null; + type = tp; + } + + internal virtual bool CanSubclass() + { + return false; + // return !type.Value.IsEnum; + } + + public void OnDeserialization(object sender) + { + throw new global::System.NotImplementedException(); + } + + internal bool HasCustomNew() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Python.System/Runtime/ClassHelper.cs b/Python.System/Runtime/ClassHelper.cs new file mode 100644 index 0000000..a396f62 --- /dev/null +++ b/Python.System/Runtime/ClassHelper.cs @@ -0,0 +1,565 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Security; +using System.Text; + + +namespace Python +{ + public static class ClassHelper + { + internal static bool ShouldBindMethod(MethodBase mb) + { + return (mb.IsPublic || mb.IsFamily || mb.IsFamilyOrAssembly); + } + + internal static bool ShouldBindField(FieldInfo fi) + { + return (fi.IsPublic || fi.IsFamily || fi.IsFamilyOrAssembly); + } + + internal static bool ShouldBindProperty(PropertyInfo pi) + { + MethodInfo mm; + try + { + mm = pi.GetGetMethod(true); + if (mm == null) + { + mm = pi.GetSetMethod(true); + } + } + catch (SecurityException) + { + // GetGetMethod may try to get a method protected by + // StrongNameIdentityPermission - effectively private. + return false; + } + + if (mm == null) + { + return false; + } + + return ShouldBindMethod(mm); + } + + internal static bool ShouldBindEvent(EventInfo ei) + { + return ShouldBindMethod(ei.GetAddMethod(true)); + } + + + + + // Binding flags to determine which members to expose in Python. + // This is complicated because inheritance in Python is name + // based. We can't just find DeclaredOnly members, because we + // could have a base class A that defines two overloads of a + // method and a class B that defines two more. The name-based + // descriptor Python will find needs to know about inherited + // overloads as well as those declared on the sub class. + internal static readonly BindingFlags BindingFlags = BindingFlags.Static | + BindingFlags.Instance | + BindingFlags.Public | + BindingFlags.NonPublic; + + + /// + /// This class owns references to PyObjects in the `members` member. + /// The caller has responsibility to DECREF them. + /// + internal class ClassInfo + { + //public Indexer? indexer; + public readonly Dictionary members = new Dictionary(); + + internal ClassInfo() + { + //indexer = null; + } + } + + + internal static ClassInfo GetClassInfo(Type type, ClassBase impl = null) + { + var ci = new ClassInfo(); + var methods = new Dictionary>(); + MethodInfo meth; + ExtensionType ob; + string name; + Type tp; + int i, n; + + MemberInfo[] info = type.GetMembers(BindingFlags); + var local = new HashSet(); + var items = new List(); + MemberInfo m; + + // Loop through once to find out which names are declared + for (i = 0; i < info.Length; i++) + { + m = info[i]; + if (m.DeclaringType == type) + { + local.Add(m.Name); + } + } + + if (type.IsEnum) + { + var opsImpl = typeof(Enum).MakeGenericType(type); + foreach (var op in opsImpl.GetMethods(OpsHelper.BindingFlags)) + { + local.Add(op.Name); + } + info = info.Concat(opsImpl.GetMethods(OpsHelper.BindingFlags)).ToArray(); + + // only [Flags] enums support bitwise operations + if (type.IsFlagsEnum()) + { + opsImpl = typeof(FlagEnumOps<>).MakeGenericType(type); + foreach (var op in opsImpl.GetMethods(OpsHelper.BindingFlags)) + { + local.Add(op.Name); + } + info = info.Concat(opsImpl.GetMethods(OpsHelper.BindingFlags)).ToArray(); + } + } + + // Now again to filter w/o losing overloaded member info + for (i = 0; i < info.Length; i++) + { + m = info[i]; + if (local.Contains(m.Name)) + { + items.Add(m); + } + } + + if (type.IsInterface) + { + // Interface inheritance seems to be a different animal: + // more contractual, less structural. Thus, a Type that + // represents an interface that inherits from another + // interface does not return the inherited interface's + // methods in GetMembers. For example ICollection inherits + // from IEnumerable, but ICollection's GetMemebers does not + // return GetEnumerator. + // + // Not sure if this is the correct way to fix this, but it + // seems to work. Thanks to Bruce Dodson for the fix. + + Type[] inheritedInterfaces = type.GetInterfaces(); + + for (i = 0; i < inheritedInterfaces.Length; ++i) + { + Type inheritedType = inheritedInterfaces[i]; + MemberInfo[] imembers = inheritedType.GetMembers(BindingFlags); + for (n = 0; n < imembers.Length; n++) + { + m = imembers[n]; + if (!local.Contains(m.Name)) + { + items.Add(m); + } + } + } + + // All interface implementations inherit from Object, + // but GetMembers don't return them either. + var objFlags = BindingFlags.Public | BindingFlags.Instance; + foreach (var mi in typeof(object).GetMembers(objFlags)) + { + if (!local.Contains(mi.Name) && (mi as ConstructorInfo) == null) + { + items.Add(mi); + } + } + } + + for (i = 0; i < items.Count; i++) + { + var mi = (MemberInfo)items[i]; + + switch (mi.MemberType) + { + #region Method + + case MemberTypes.Method: + meth = (MethodInfo)mi; + if (!ShouldBindMethod(meth)) + { + continue; + } + name = meth.Name; + + //TODO mangle? + if (name == "__init__" && impl != null && !impl.HasCustomNew()) + continue; + + if (!methods.TryGetValue(name, out var methodList)) + { + methodList = methods[name] = new List(); + } + methodList.Add(meth); + continue; + + #endregion + + #region Constructor + case MemberTypes.Constructor when (impl != null && !impl.HasCustomNew()): + var ctor = (ConstructorInfo)mi; + if (ctor.IsStatic) + { + continue; + } + + name = "__init__"; + if (!methods.TryGetValue(name, out methodList)) + { + methodList = methods[name] = new List(); + } + methodList.Add(ctor); + continue; + #endregion + + #region Property + case MemberTypes.Property: + var pi = (PropertyInfo)mi; + + if (!ShouldBindProperty(pi)) + { + continue; + } + + // Check for indexer + ParameterInfo[] args = pi.GetIndexParameters(); + + if (args.GetLength(0) > 0) + { +#if Indexer + Indexer? idx = ci.indexer; + if (idx == null) + { + ci.indexer = new Indexer(); + idx = ci.indexer; + } + idx.AddProperty(pi); +#endif + continue; + } + + ob = new PropertyObject(pi); + ci.members[pi.Name] = ob.AllocObject(); + continue; + + #endregion + + #region Field + case MemberTypes.Field: + var fi = (FieldInfo)mi; + if (!ShouldBindField(fi)) + { + continue; + } + ob = new FieldObject(fi); + ci.members[mi.Name] = ob.AllocObject(); + continue; + #endregion + + #region Event + case MemberTypes.Event: + var ei = (EventInfo)mi; + if (!ShouldBindEvent(ei)) + { + continue; + } + ob = ei.AddMethod.IsStatic + ? (ExtensionType)new EventBinding(ei) + : new EventObject(ei); + ci.members[ei.Name] = ob.AllocObject(); + continue; + #endregion + +#if NestedType + case MemberTypes.NestedType: + tp = (Type)mi; + if (!(tp.IsNestedPublic || tp.IsNestedFamily || + tp.IsNestedFamORAssem)) + { + continue; + } + // Note the given instance might be uninitialized + var pyType = GetClass(tp); + // make a copy, that could be disposed later + ci.members[mi.Name] = new ReflectedClrType(pyType); + continue; +#endif + } + } + + foreach (var iter in methods) + { + name = iter.Key; + MethodBase[] mlist = iter.Value.ToArray(); + + ob = new MethodObject(type, name, mlist); + ci.members[name] = (MethodObject)ob.AllocObject(); + +#if false + + if (mlist.Any(OperatorMethod.IsOperatorMethod)) + { + string pyName = OperatorMethod.GetPyMethodName(name); + string pyNameReverse = OperatorMethod.ReversePyMethodName(pyName); + OperatorMethod.FilterMethods(mlist, out var forwardMethods, out var reverseMethods); + // Only methods where the left operand is the declaring type. + if (forwardMethods.Length > 0) + ci.members[pyName] = new MethodObject(type, name, forwardMethods).AllocObject(); + // Only methods where only the right operand is the declaring type. + if (reverseMethods.Length > 0) + ci.members[pyNameReverse] = new MethodObject(type, name, reverseMethods).AllocObject(); + } + +#endif + } + +#if false + if (ci.indexer == null && type.IsClass) + { + // Indexer may be inherited. + var parent = type.BaseType; + while (parent != null && ci.indexer == null) + { + foreach (var prop in parent.GetProperties()) + { + var args = prop.GetIndexParameters(); + if (args.GetLength(0) > 0) + { + ci.indexer = new Indexer(); + ci.indexer.AddProperty(prop); + break; + } + } + parent = parent.BaseType; + } + } +#endif + + return ci; + } + + +#if false + private static ClassInfo GetClassInfo(Type type) + { + ClassInfo ci = new ClassInfo(); + Hashtable methods = new Hashtable(); + ArrayList list; + MethodInfo meth; + ManagedType ob; + String name; + Object item; + Type tp; + int i, n; + + // This is complicated because inheritance in Python is name + // based. We can't just find DeclaredOnly members, because we + // could have a base class A that defines two overloads of a + // method and a class B that defines two more. The name-based + // descriptor Python will find needs to know about inherited + // overloads as well as those declared on the sub class. + + BindingFlags flags = BindingFlags.Static | + BindingFlags.Instance | + BindingFlags.Public | + BindingFlags.NonPublic; + + MemberInfo[] info = type.GetMembers(flags); + Hashtable local = new Hashtable(); + ArrayList items = new ArrayList(); + MemberInfo m; + + // Loop through once to find out which names are declared + for (i = 0; i < info.Length; i++) + { + m = info[i]; + if (m.DeclaringType == type) + { + local[m.Name] = 1; + } + } + + // Now again to filter w/o losing overloaded member info + for (i = 0; i < info.Length; i++) + { + m = info[i]; + if (local[m.Name] != null) + { + items.Add(m); + } + } + + if (type.IsInterface) + { + // Interface inheritance seems to be a different animal: + // more contractual, less structural. Thus, a Type that + // represents an interface that inherits from another + // interface does not return the inherited interface's + // methods in GetMembers. For example ICollection inherits + // from IEnumerable, but ICollection's GetMemebers does not + // return GetEnumerator. + // + // Not sure if this is the correct way to fix this, but it + // seems to work. Thanks to Bruce Dodson for the fix. + + Type[] inheritedInterfaces = type.GetInterfaces(); + + for (i = 0; i < inheritedInterfaces.Length; ++i) + { + Type inheritedType = inheritedInterfaces[i]; + MemberInfo[] imembers = inheritedType.GetMembers(flags); + for (n = 0; n < imembers.Length; n++) + { + m = imembers[n]; + if (local[m.Name] == null) + { + items.Add(m); + } + } + } + } + + for (i = 0; i < items.Count; i++) + { + + MemberInfo mi = (MemberInfo)items[i]; + + switch (mi.MemberType) + { + + #region Method + case MemberTypes.Method: + meth = (MethodInfo)mi; + if (!(meth.IsPublic || meth.IsFamily || + meth.IsFamilyOrAssembly)) + continue; + name = meth.Name; + item = methods[name]; + if (item == null) + { + item = methods[name] = new ArrayList(); + } + list = (ArrayList)item; + list.Add(meth); + continue; + #endregion + + #region Property + + case MemberTypes.Property: + PropertyInfo pi = (PropertyInfo)mi; + + MethodInfo mm = null; + try + { + mm = pi.GetGetMethod(true); + if (mm == null) + { + mm = pi.GetSetMethod(true); + } + } + catch (SecurityException) + { + // GetGetMethod may try to get a method protected by + // StrongNameIdentityPermission - effectively private. + continue; + } + + if (mm == null) + { + continue; + } + + if (!(mm.IsPublic || mm.IsFamily || mm.IsFamilyOrAssembly)) + continue; + + // Check for indexer + ParameterInfo[] args = pi.GetIndexParameters(); + if (args.GetLength(0) > 0) + { + Indexer idx = ci.indexer; + if (idx == null) + { + ci.indexer = new Indexer(); + idx = ci.indexer; + } + idx.AddProperty(pi); + continue; + } + + ob = new PropertyObject(pi); + ci.members[pi.Name] = ob; + continue; + + #endregion + + #region Field + case MemberTypes.Field: + FieldInfo fi = (FieldInfo)mi; + if (!(fi.IsPublic || fi.IsFamily || fi.IsFamilyOrAssembly)) + continue; + ob = new FieldObject(fi); + ci.members[mi.Name] = ob; + continue; + #endregion + + case MemberTypes.Event: + EventInfo ei = (EventInfo)mi; + MethodInfo me = ei.GetAddMethod(true); + if (!(me.IsPublic || me.IsFamily || me.IsFamilyOrAssembly)) + continue; + ob = new EventObject(ei); + ci.members[ei.Name] = ob; + continue; + + case MemberTypes.NestedType: + tp = (Type)mi; + if (!(tp.IsNestedPublic || tp.IsNestedFamily || + tp.IsNestedFamORAssem)) + continue; + ob = ClassManager.GetClass(tp); + ci.members[mi.Name] = ob; + continue; + + } + } + + IDictionaryEnumerator iter = methods.GetEnumerator(); + + while (iter.MoveNext()) + { + name = (string)iter.Key; + list = (ArrayList)iter.Value; + + MethodInfo[] mlist = (MethodInfo[])list.ToArray( + typeof(MethodInfo) + ); + + ob = new MethodObject(name, mlist); + ci.members[name] = ob; + } + + return ci; + + } + +#endif + } + + +} diff --git a/Python.System/Runtime/ExtensionType.cs b/Python.System/Runtime/ExtensionType.cs new file mode 100644 index 0000000..f198e50 --- /dev/null +++ b/Python.System/Runtime/ExtensionType.cs @@ -0,0 +1,85 @@ +using System; +using System.Reflection; + +using System = System; + +namespace Python +{ + internal class ExtensionType + { + private EventInfo ei; + + public ExtensionType(EventInfo ei = null) + { + this.ei = ei; + } + + internal virtual object AllocObject() + { + return this; + } + + } + internal class PropertyObject : ExtensionType + { + private PropertyInfo pi; + + public PropertyObject(PropertyInfo pi) + { + this.pi = pi; + } + } + + internal class MethodObject : ExtensionType + { + private Type type; + public string name; + public MethodBase[] mlist; + + public MethodObject(Type type, string name, MethodBase[] mlist) + { + this.type = type; + this.name = name; + this.mlist = mlist; + } + internal new object AllocObject() + { + return this; + } + } + + internal class FieldObject : ExtensionType + { + public FieldInfo fi; + + public FieldObject(FieldInfo fi) + { + this.fi = fi; + } + internal override object AllocObject() + { + return this; + // todo + // FIXME + object instance = Activator.CreateInstance(fi.DeclaringType); // 使用反射创建实例 + return instance; + } + } + + internal class EventObject : ExtensionType + { + public EventObject(EventInfo ei) : base(ei) + { + } + } + internal class EventBinding : ExtensionType + { + + public EventBinding(EventInfo ei) : base(ei) + { + + } + + } + +} \ No newline at end of file diff --git a/Python.System/Runtime/ManagedType.cs b/Python.System/Runtime/ManagedType.cs new file mode 100644 index 0000000..2b4116b --- /dev/null +++ b/Python.System/Runtime/ManagedType.cs @@ -0,0 +1,6 @@ +namespace Python +{ + internal class ManagedType + { + } +} \ No newline at end of file diff --git a/Python.System/Runtime/OpsHelper.cs b/Python.System/Runtime/OpsHelper.cs new file mode 100644 index 0000000..c013561 --- /dev/null +++ b/Python.System/Runtime/OpsHelper.cs @@ -0,0 +1,99 @@ +//copy from https://github.com/pythonnet/pythonnet/blob/95c1371eaccacbcb4e32ec1c8654c625cc85619a/src/runtime/Util/OpsHelper.cs + +using System; +using System.Linq.Expressions; +using System.Reflection; + +using static Python.OpsHelper; + +namespace Python +{ + internal static class OpsHelper + { + public static BindingFlags BindingFlags => BindingFlags.Public | BindingFlags.Static; + + public static Func Binary(Func func) + { + var a = Expression.Parameter(typeof(T), "a"); + var b = Expression.Parameter(typeof(T), "b"); + var body = func(a, b); + var lambda = Expression.Lambda>(body, a, b); + return lambda.Compile(); + } + + public static Func Unary(Func func) + { + var value = Expression.Parameter(typeof(T), "value"); + var body = func(value); + var lambda = Expression.Lambda>(body, value); + return lambda.Compile(); + } + + public static bool IsOpsHelper(this MethodBase method) + => method.DeclaringType.GetCustomAttribute() != null; + + public static Expression EnumUnderlyingValue(Expression enumValue) + => Expression.Convert(enumValue, enumValue.Type.GetEnumUnderlyingType()); + } + + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] + internal class OpsAttribute : Attribute { } + + [Ops] + internal static class FlagEnumOps where T : Enum + { + static readonly Func and = BinaryOp(Expression.And); + static readonly Func or = BinaryOp(Expression.Or); + static readonly Func xor = BinaryOp(Expression.ExclusiveOr); + + static readonly Func invert = UnaryOp(Expression.OnesComplement); + +#pragma warning disable IDE1006 + public static T op_BitwiseAnd(T a, T b) => and(a, b); + public static T op_BitwiseOr(T a, T b) => or(a, b); + public static T op_ExclusiveOr(T a, T b) => xor(a, b); + public static T op_OnesComplement(T value) => invert(value); +#pragma warning restore IDE1006 + + static Expression FromNumber(Expression number) + => Expression.Convert(number, typeof(T)); + + static Func BinaryOp(Func op) + { + return Binary((a, b) => + { + var numericA = EnumUnderlyingValue(a); + var numericB = EnumUnderlyingValue(b); + var numericResult = op(numericA, numericB); + return FromNumber(numericResult); + }); + } + static Func UnaryOp(Func op) + { + return Unary(value => + { + var numeric = EnumUnderlyingValue(value); + var numericResult = op(numeric); + return FromNumber(numericResult); + }); + } + } + +#if false + [Ops] + internal static class EnumOps where T : Enum + { + [ForbidPythonThreads] +#pragma warning disable IDE1006 // Naming Styles - must match Python + public static PyInt __index__(T value) +#pragma warning restore IDE1006 // Naming Styles + => typeof(T).GetEnumUnderlyingType() == typeof(UInt64) + ? new PyInt(Convert.ToUInt64(value)) + : new PyInt(Convert.ToInt64(value)); + [ForbidPythonThreads] +#pragma warning disable IDE1006 // Naming Styles - must match Python + public static PyInt __int__(T value) => __index__(value); +#pragma warning restore IDE1006 // Naming Styles + } +#endif +} diff --git a/Python.System/Runtime/ReflectionPolyfills.cs b/Python.System/Runtime/ReflectionPolyfills.cs new file mode 100644 index 0000000..d19974b --- /dev/null +++ b/Python.System/Runtime/ReflectionPolyfills.cs @@ -0,0 +1,39 @@ +//copy from https://github.com/pythonnet/pythonnet/blob/95c1371eaccacbcb4e32ec1c8654c625cc85619a/src/runtime/Util/ReflectionPolyfills.cs + +using System; +using System.Linq; +using System.Reflection; +using System.Reflection.Emit; + +namespace Python +{ + internal static class ReflectionPolyfills + { + public static AssemblyBuilder DefineDynamicAssembly(this AppDomain _, AssemblyName assemblyName, AssemblyBuilderAccess assemblyBuilderAccess) + { + return AssemblyBuilder.DefineDynamicAssembly(assemblyName, assemblyBuilderAccess); + } + + public static Type CreateType(this TypeBuilder typeBuilder) + { + return typeBuilder.CreateTypeInfo(); + } + + public static T GetCustomAttribute(this Type type) where T : Attribute + { + return type.GetCustomAttributes(typeof(T), inherit: false) + .Cast() + .SingleOrDefault(); + } + + public static T GetCustomAttribute(this Assembly assembly) where T : Attribute + { + return assembly.GetCustomAttributes(typeof(T), inherit: false) + .Cast() + .SingleOrDefault(); + } + + public static bool IsFlagsEnum(this Type type) + => type.GetCustomAttribute() != null; + } +} From 0941d16a8b815acaa5c70c006b8cb8ad8a549e64 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 01:37:09 +0800 Subject: [PATCH 30/74] =?UTF-8?q?-=20=E6=94=AF=E6=8C=81=20help=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E3=80=82=20=E6=AC=A2=E8=BF=8E=20pr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Python.System/Python/help.cs | 108 +++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 Python.System/Python/help.cs diff --git a/Python.System/Python/help.cs b/Python.System/Python/help.cs new file mode 100644 index 0000000..d5f9060 --- /dev/null +++ b/Python.System/Python/help.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Text; + + +namespace Python +{ + public partial class System + { + public static void Help() + { + + } + + + + /// + /// 启动内置的帮助系统(此函数主要在交互式中使用)。 + /// 如果实参是一个字符串,则在模块、函数、类、方法、关键字或文档主题中搜索该字符串,并在控制台上打印帮助信息。 + /// 如果实参是其他任意对象,则会生成该对象的帮助页。 + /// + /// + /// + public static void Help(object request) => help(request.GetType()); + + /// + /// 启动内置的帮助系统(此函数主要在交互式中使用)。 + /// 如果实参是一个字符串,则在模块、函数、类、方法、关键字或文档主题中搜索该字符串,并在控制台上打印帮助信息。 + /// 如果实参是其他任意对象,则会生成该对象的帮助页。 + /// + /// + /// + + public static void Help(Type request) => help(request); + + + + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] +#endif + public static void help() + { + print("Welcome to the Python.System, Welcome PRs => https://github.com/heartacker/Python.System"); + } + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] +#endif + public static void help(object request) => help(request.GetType()); + + + // //如果没有实参,解释器控制台里会启动交互式帮助系统。 + + /// + /// 启动内置的帮助系统(此函数主要在交互式中使用)。 + /// 如果实参是一个字符串,则在模块、函数、类、方法、关键字或文档主题中搜索该字符串,并在控制台上打印帮助信息。 + /// 如果实参是其他任意对象,则会生成该对象的帮助页。 + /// + /// + /// + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] +#endif + public static void help(Type request) + { + ClassHelper.ClassInfo c = ClassHelper.GetClassInfo(request); + var sb = new StringBuilder(); + + sb.AppendLine("================================================================="); + + sb.AppendLine("Name\t\t" + request.FullName); + sb.AppendLine("Assembly\t\t\t" + request.Assembly.FullName); + sb.AppendLine(); + sb.AppendLine("field:"); + sb.AppendLine("----------------------------------------------------------------"); + + foreach (var item in c.members) + { + if (item.Value is FieldObject) + { + sb.AppendLine($"{item.Key}:\t\t\t{((FieldObject)item.Value).fi}"); + } + } + sb.AppendLine(); + sb.AppendLine("Method:"); + sb.AppendLine("----------------------------------------------------------------"); + + foreach (var item in c.members) + { + if (item.Value is MethodObject) + { + sb.AppendLine($"{item.Key}:\t\t\t{((MethodObject)item.Value).mlist[0].ToString()}"); + } + } + sb.AppendLine(); + sb.AppendLine("================================================================="); + sb.AppendLine(); + Console.Write(sb.ToString()); + } + } +} \ No newline at end of file From 769b041b1f781e3174a93886733c30c21b3cfb45 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 01:37:26 +0800 Subject: [PATCH 31/74] =?UTF-8?q?=E5=8E=BB=E9=99=A4pythonnet=20=E7=9A=84?= =?UTF-8?q?=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Python.System/Python.System.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python.System/Python.System.csproj b/Python.System/Python.System.csproj index f5fae08..e6645eb 100644 --- a/Python.System/Python.System.csproj +++ b/Python.System/Python.System.csproj @@ -21,7 +21,7 @@ - + From a65eb7c5f054be3449f04ac007ac92c39fd2f76c Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 02:02:47 +0800 Subject: [PATCH 32/74] "Hello Python.System" --- Python.SystemDemo/Properties/launchSettings.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Python.SystemDemo/Properties/launchSettings.json diff --git a/Python.SystemDemo/Properties/launchSettings.json b/Python.SystemDemo/Properties/launchSettings.json new file mode 100644 index 0000000..1f5332b --- /dev/null +++ b/Python.SystemDemo/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "Python.SystemDemo": { + "commandName": "Project", + "commandLineArgs": "Hello Python.System" + } + } +} \ No newline at end of file From 1448d78a6ee548916e351b3f0a6d11897bd90cae Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 02:11:21 +0800 Subject: [PATCH 33/74] changelog and readme --- CHANGELOG.md | 12 ++++ README.md | 175 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 178 insertions(+), 9 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..9005132 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +# changelog +## unreleased +nothing + +## released + +- version: 1.0.5-pre + - time: 2023年5月14日 + - log: + 1. change readme + 2. add `help` function + 3. add `dir` function \ No newline at end of file diff --git a/README.md b/README.md index b2b9eec..0a4daa6 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,55 @@ -# Python.System +# 1. Python.System [![GitHub stars](https://img.shields.io/github/stars/heartacker/Python.System?style=for-the-badge)](https://github.com/heartacker/Python.System) [![Nuget](https://img.shields.io/nuget/v/Python.System?style=for-the-badge)](https://www.nuget.org/packages/Python.System) ![Nuget](https://img.shields.io/nuget/dt/Python.System?style=for-the-badge) [![GitHub release](https://img.shields.io/github/v/release/heartacker/Python.System?style=for-the-badge)](https://github.com/heartacker/Python.System/releases) + + + + +- [1. Python.System](#1-pythonsystem) + - [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** 我们主要是想在 `C#` 实现 **`Python` 的内置函数**,并**在`C#` 中可以直接使用**, 以便提高简单脚本的编写效率。 We aim to implement the **built-in function of python in `C#`** and **direct use in `C#`** to improve the effect. -## demo +## 1.2. Recent Changelog + +- time: 2023年5月14日 +- version: 1.0.5-pre +- log: + 1. change readme + 2. add `help` function + 3. add `dir` function -- code + +more information, see [CHANGELOG.md](https://github.com/heartacker/Python.System/CHANGELOG.md) + +## 1.3. Demo + +- `Code`
-🔗 [ **C#** ](./Python.System.Demo.csx) +🔗 [**C#**](./Python.System.Demo.csx) ```csharp #r "nuget: Python.System, *" @@ -49,7 +78,7 @@ print(c, sep:"\t"); -🔗 [ **Python** ](./Python.System.Compare.py) +🔗 [**Python**](./Python.System.Compare.py) ```python #r @@ -79,7 +108,7 @@ print(c, sep="\t")
-- output +- `Output`
@@ -94,7 +123,7 @@ print(c, sep="\t") 305419896 0b10010001101000101011001111000 0 1 2 3 4 5 6 7 -0 1 2 3 4 5 6 7 +0 1 2 3 4 5 6 7 ``` @@ -119,7 +148,7 @@ print(c, sep="\t")
-## [dotnet script and repl](https://github.com/dotnet-script/dotnet-script#repl) +## 1.4. [dotnet script and repl](https://github.com/dotnet-script/dotnet-script#repl) ```shell ~$ dotnet-script @@ -130,4 +159,132 @@ print(c, sep="\t") > print("Hello Scripy") Hello Scripy -``` \ No newline at end of file +``` + +## 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()`](./Python.System/Python/abs.cs) + - [ ] `aiter()` + - [x] [`all()`](./Python.System/Python/all.cs) + - [x] [`any()`](./Python.System/Python/any.cs) + - [ ] `anext()` + - [ ] `ascii()` + +- B + - [x] [`bin()`](./Python.System/Python/bin.cs) + - [ ] `bool()` + - [ ] `breakpoint()` + - [x] [`bytearray()`](./Python.System/Python/bytearry.cs) + - [x] [`bytes()`](./Python.System/Python/bytearry.cs) + +- C + - [ ] `callable()` + - [x] [`chr()`](./Python.System/Python/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()`](./Python.System/Python/help.cs) + - [x] [`hex()`](./Python.System/Python/hex.cs) + +- I + - [ ] `id()` + - [ ] `input()` + - [ ] `int()` + - [ ] `isinstance()` + - [ ] `issubclass()` + - [ ] `iter()` + +- L + - [ ] `len()` + - [ ] `list()` + - [ ] `locals()` + +- M + - [ ] `map()` + - [ ] `max()` + - [ ] `memoryview()` + - [ ] `min()` + +- N + - [ ] `next()` + +- O + - [ ] `object()` + - [ ] `oct()` + - [ ] `open()` + - [x] [`ord()`](./Python.System/Python/ord.cs) + +- P + - [ ] `pow()` + - [x] [`print()`](./Python.System/Python/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__()` + - [ ] ??? From 1f2ac36d36b65bd146a4f522cd8a2503f4c30046 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 02:12:00 +0800 Subject: [PATCH 34/74] demo --- Python.SystemDemo/SystemDemo.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Python.SystemDemo/SystemDemo.cs b/Python.SystemDemo/SystemDemo.cs index c0b44aa..cac4a8d 100644 --- a/Python.SystemDemo/SystemDemo.cs +++ b/Python.SystemDemo/SystemDemo.cs @@ -1,8 +1,4 @@ using static Python.System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Python.SystemDemo { @@ -15,6 +11,18 @@ public static void Main(string[] args) print("hello world"); print(a); print(a, sep: "\t"); + + + var eargs = Environment.GetCommandLineArgs(); + + print(eargs); + + help(); + + help(a); + help(typeof(Math)); + help(typeof(Python.System)); } + } } \ No newline at end of file From e362c03efe96f8a4850e643477539c3291b6aeb6 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 02:31:59 +0800 Subject: [PATCH 35/74] notebook demo --- Python.System.Demo.dib | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Python.System.Demo.dib b/Python.System.Demo.dib index 5006eb4..9850110 100644 --- a/Python.System.Demo.dib +++ b/Python.System.Demo.dib @@ -2,14 +2,36 @@ {"kernelInfo":{"defaultKernelName":"csharp","items":[{"aliases":[],"languageName":"csharp","name":"csharp"}]}} +#!markdown + +## Python.System + +demo of Python.System + +#!markdown + +## ref the package +- ref nuget package + #!csharp #r "nuget: Python.System, *" +#!markdown + +- using the static functions in `Python.System` + #!csharp using static Python.System; +#!markdown + +## usage +write script like python + +#!csharp + var addr = 0x12345678; var addrr = hex(addr); @@ -31,3 +53,13 @@ print(c, sep:"\t"); var _12 = abs(-15.6); print(_12); + +#!markdown + +### help + +#!csharp + +help(typeof(System.Math)); + +help(typeof(System.IO.File)); From 104307b21751d0a253cb3b4872457c65a62c2532 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 02:39:28 +0800 Subject: [PATCH 36/74] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0a4daa6..b40828e 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ - [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.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) @@ -38,7 +38,7 @@ We aim to implement the **built-in function of python in `C#`** and **direct use 3. add `dir` function -more information, see [CHANGELOG.md](https://github.com/heartacker/Python.System/CHANGELOG.md) +more information, see [CHANGELOG.md](https://github.com/heartacker/Python.System/blob/master/CHANGELOG.md) ## 1.3. Demo @@ -148,7 +148,7 @@ print(c, sep="\t") -## 1.4. [dotnet script and repl](https://github.com/dotnet-script/dotnet-script#repl) +## 1.4. [Dotnet script and repl](https://github.com/dotnet-script/dotnet-script#repl) ```shell ~$ dotnet-script From 4bf1697e2ec7db70db0918dde2f49bd2cdc27fda Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 09:44:06 +0800 Subject: [PATCH 37/74] oct --- Python.System/Python/bin.cs | 1 - Python.System/Python/oct.cs | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Python.System/Python/oct.cs diff --git a/Python.System/Python/bin.cs b/Python.System/Python/bin.cs index da897b6..787e41b 100644 --- a/Python.System/Python/bin.cs +++ b/Python.System/Python/bin.cs @@ -1,5 +1,4 @@ using System; -using System.Numerics; namespace Python { diff --git a/Python.System/Python/oct.cs b/Python.System/Python/oct.cs new file mode 100644 index 0000000..e41b0e1 --- /dev/null +++ b/Python.System/Python/oct.cs @@ -0,0 +1,49 @@ +using System; + +namespace Python +{ + public partial class System + { + #region oct + public static string Oct(long x, int? width = null) + => oct(x, width); + + + + + + + /// + /// εתΪ8 + /// + /// + /// λ 򲻹עתλȡλ + /// ַ +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(bin)}` instead.")] +#endif + public static string oct(long x, int? width = null) + { + if (width == null || width <= 0) + { + return "0o" + Convert.ToString(x, 8); + } + else + { + string format = Convert.ToString(x, 8); + if (format.Length < width) + { + string par = ""; + for (int c = 0; c < width - format.Length; c++) + { + par += "0"; + } + return "0o" + par + format; + } + return "0o" + format; + } + } + + #endregion + } +} From 2686db1759793d5a3e660a008fb1843b9a91f292 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 09:44:27 +0800 Subject: [PATCH 38/74] trim the last character --- Python.System/Python/print.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Python.System/Python/print.cs b/Python.System/Python/print.cs index ee6a451..699a964 100644 --- a/Python.System/Python/print.cs +++ b/Python.System/Python/print.cs @@ -16,7 +16,7 @@ public static void Print(object @object, bool flush = false) => print(@object, sep, end, file, flush); - public static void Print(IList @object, + public static void Print(IEnumerable @object, string sep = " ", string end = "\r\n", StreamWriter file = null, @@ -45,18 +45,23 @@ public static void print(object @object, #if OBSOLETE [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] #endif - public static void print(IList @object, + public static void print(IEnumerable @object, string sep = " ", string end = "\r\n", StreamWriter file = null, bool flush = false) { var _file = file ?? Console.Out; + string str = ""; foreach (var item in @object) { - _file.Write(item.ToString()); - _file.Write(sep); + str += item.ToString(); + str += sep; } + + str = str.Remove(str.Length - sep.Length, sep.Length); + + _file.Write(str); _file.Write(end); if (flush) _file.Flush(); } From 5c62b7fba1968aca149628b750b06ba290acf75e Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 09:47:22 +0800 Subject: [PATCH 39/74] testcode --- Python.SystemTests/SystemTests.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Python.SystemTests/SystemTests.cs b/Python.SystemTests/SystemTests.cs index b64a164..9bfd276 100644 --- a/Python.SystemTests/SystemTests.cs +++ b/Python.SystemTests/SystemTests.cs @@ -43,5 +43,22 @@ public void printTest(string abcs) { print(abcs); } + + + [TestMethod()] + public void printTestSep() + { + int[] c = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }; + print(c, "+"); + } + + [TestMethod()] + [DataRow(8, "0o10")] + [DataRow(0x12345678, "0o2215053170")] + + public void octTest(long x, string res) + { + Assert.AreEqual(res, oct(x)); + } } } \ No newline at end of file From 43e03a706b5ec77b1e00eabdf84f03c45e599ecd Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 09:47:30 +0800 Subject: [PATCH 40/74] demo --- Python.System.Demo.dib | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Python.System.Demo.dib b/Python.System.Demo.dib index 9850110..0267d4c 100644 --- a/Python.System.Demo.dib +++ b/Python.System.Demo.dib @@ -15,7 +15,7 @@ demo of Python.System #!csharp -#r "nuget: Python.System, *" +#r "nuget: Python.System, 1.0.6-debug4" #!markdown @@ -34,20 +34,27 @@ write script like python var addr = 0x12345678; var addrr = hex(addr); - +print("hex"); print(addr); // 305419896 print(addrr); var val = 0x12345678; var valr = bin(addr); - +print("bin"); print(val); // 305419896 print(valr); +var octs = 0x12345678; +var octr = oct(octs); +print("oct"); +print(octs); // 305419896 +print(octr); + var c = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }; print(c); print(c, sep:"\t"); +print(c, sep:"+"); #!csharp From e4d9be3cda36a148bce562bbd5d5c4283d5af6e5 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 09:47:46 +0800 Subject: [PATCH 41/74] update readme --- README.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b40828e..d91adef 100644 --- a/README.md +++ b/README.md @@ -24,18 +24,27 @@ **write c# script like python** -我们主要是想在 `C#` 实现 **`Python` 的内置函数**,并**在`C#` 中可以直接使用**, 以便提高简单脚本的编写效率。 +!!! done 思路 + 我们主要是想在 `C#` 实现 **`Python` 的内置函数**,并**在`C#` 中可以直接使用**, 以便提高简单脚本的编写效率。 -We aim to implement the **built-in function of python in `C#`** and **direct use in `C#`** to improve the effect. + !!! tip 欢迎 ❤️ + 欢迎 任何 PR + +!!! done idea + We aim to implement the **built-in function of python in `C#`** and **direct use in `C#`** to improve the effect. + + !!! done **Welcome** ❤️ + welcome any pull request ## 1.2. Recent Changelog -- time: 2023年5月14日 -- version: 1.0.5-pre +- 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 sep more information, see [CHANGELOG.md](https://github.com/heartacker/Python.System/blob/master/CHANGELOG.md) From 2ff6b757002552ed588dae43150bdfc3f8c83b75 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 09:53:43 +0800 Subject: [PATCH 42/74] v1.0.6 --- Python.System/Python.System.csproj | 8 ++++---- README.md | 15 +++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Python.System/Python.System.csproj b/Python.System/Python.System.csproj index e6645eb..3747a80 100644 --- a/Python.System/Python.System.csproj +++ b/Python.System/Python.System.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 @@ -15,13 +15,13 @@ https://github.com/heartacker/Static.System.git git static;python;function;script; - 初始化版本。添加 hex,bin,print 函数 + see https://github.com/heartacker/Python.System/blob/master/CHANGELOG.md 0.0.0.2 - 1.0.5 + 1.0.6 - + diff --git a/README.md b/README.md index d91adef..d463272 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,6 @@ 3. add `dir` function 4. fix trim `print()` last sep - more information, see [CHANGELOG.md](https://github.com/heartacker/Python.System/blob/master/CHANGELOG.md) ## 1.3. Demo @@ -90,7 +89,7 @@ print(c, sep:"\t"); 🔗 [**Python**](./Python.System.Compare.py) ```python -#r +#r "nuget: Python.System, *" addr = 0x12345678 @@ -173,14 +172,14 @@ Hello Scripy ## 1.5. Extended function list - MyOwn - - [ ] load() - - [ ] unload() + - [ ] `load()` + - [ ] `unload()` ## 1.6. Extended function list like `Matlab` - coming - - [ ] ??? - - [ ] ???? + - [ ] `???` + - [ ] `????` ## 1.7. `Python` Built-in function list @@ -257,7 +256,7 @@ Hello Scripy - O - [ ] `object()` - - [ ] `oct()` + - [x] [`oct()`](./Python.System/Python/oct.cs) - [ ] `open()` - [x] [`ord()`](./Python.System/Python/ord.cs) @@ -296,4 +295,4 @@ Hello Scripy - misc - [ ] `_` - [ ] `__import__()` - - [ ] ??? + - [ ] `???` From 154ac7cf923243ff91629eaae5358d8108a4e47a Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 11:11:59 +0800 Subject: [PATCH 43/74] fix print --- Python.System/Python/print.cs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Python.System/Python/print.cs b/Python.System/Python/print.cs index 699a964..5a555ac 100644 --- a/Python.System/Python/print.cs +++ b/Python.System/Python/print.cs @@ -52,17 +52,25 @@ public static void print(IEnumerable @object, bool flush = false) { var _file = file ?? Console.Out; - string str = ""; - foreach (var item in @object) + if (@object is String) { - str += item.ToString(); - str += sep; + _file.Write(@object); + _file.Write(end); } + else + { + string str = ""; + foreach (var item in @object) + { + str += item.ToString(); + str += sep; + } - str = str.Remove(str.Length - sep.Length, sep.Length); + str = str.Remove(str.Length - sep.Length, sep.Length); - _file.Write(str); - _file.Write(end); + _file.Write(str); + _file.Write(end); + } if (flush) _file.Flush(); } #endregion From ad22b2c9d9084cb23123bb481c173bf0ff6f742b Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 11:13:23 +0800 Subject: [PATCH 44/74] demo and launch --- .vscode/launch.json | 14 +++++++++++++- .vscode/tasks.json | 21 ++++++++++++++++++++- Python.System.Demo.dib | 2 +- Python.SystemDemo/SystemDemo.cs | 6 +++--- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 06624b2..68e3d1d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -26,6 +26,18 @@ ], "cwd": "${workspaceRoot}", "stopAtEntry": false - } + }, + { + "name": "demo", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "buildDemo", + "program": "${workspaceFolder}/Python.SystemDemo/bin/Debug/net7.0-windows/Python.SystemDemo.exe", + "requireExactSource": false, + "args": [], + "cwd": "${workspaceFolder}", + "stopAtEntry": false, + "console": "internalConsole" + }, ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b675f5b..562cc11 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -16,6 +16,25 @@ "reveal": "silent" }, "problemMatcher": "$msCompile" - } + }, + { + "label": "buildDemo", + "command": "dotnet", + "type": "shell", + "args": [ + "build", + "${workspaceFolder}/Python.SystemDemo/Python.SystemDemo.csproj", + // Ask dotnet build to generate full paths for file names. + "/property:GenerateFullPaths=true", + // Do not generate summary otherwise it leads to duplicate errors in Problems panel + "/consoleloggerparameters:NoSummary", + "-p:Configuration=Debug", + ], + "group": "build", + "presentation": { + "reveal": "silent" + }, + "problemMatcher": "$msCompile" + }, ] } \ No newline at end of file diff --git a/Python.System.Demo.dib b/Python.System.Demo.dib index 0267d4c..5cff10b 100644 --- a/Python.System.Demo.dib +++ b/Python.System.Demo.dib @@ -15,7 +15,7 @@ demo of Python.System #!csharp -#r "nuget: Python.System, 1.0.6-debug4" +#r "nuget: Python.System, *" #!markdown diff --git a/Python.SystemDemo/SystemDemo.cs b/Python.SystemDemo/SystemDemo.cs index cac4a8d..b669383 100644 --- a/Python.SystemDemo/SystemDemo.cs +++ b/Python.SystemDemo/SystemDemo.cs @@ -6,16 +6,16 @@ public class Demo { public static void Main(string[] args) { + var eargs = Environment.GetCommandLineArgs(); + print(eargs); + print("hello world"); uint[] a = { 1, 2, 3, 4, 5, 6, 7 }; - print("hello world"); print(a); print(a, sep: "\t"); - var eargs = Environment.GetCommandLineArgs(); - print(eargs); help(); From 06dde9041adec01a0dfdf5f49f464359a10ff7a3 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 11:17:13 +0800 Subject: [PATCH 45/74] 1.0.7 --- Python.System/Python.System.csproj | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Python.System/Python.System.csproj b/Python.System/Python.System.csproj index 3747a80..ab182ff 100644 --- a/Python.System/Python.System.csproj +++ b/Python.System/Python.System.csproj @@ -8,7 +8,9 @@ True Static System function Like Python heartacker - provide some static funtion that like python and write c# some like Python + provide some static funtion that like python and write c# some like Python + see https://github.com/heartacker/Static.System.git + MIT S.System.png @@ -17,7 +19,7 @@ static;python;function;script; see https://github.com/heartacker/Python.System/blob/master/CHANGELOG.md 0.0.0.2 - 1.0.6 + 1.0.7 @@ -31,4 +33,4 @@ - + \ No newline at end of file From e85990522fbf43479fe3944e26334cefb98c59d3 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 11:23:07 +0800 Subject: [PATCH 46/74] tip --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d463272..3afdb8d 100644 --- a/README.md +++ b/README.md @@ -24,16 +24,16 @@ **write c# script like python** -!!! done 思路 +!!! tip 思路 我们主要是想在 `C#` 实现 **`Python` 的内置函数**,并**在`C#` 中可以直接使用**, 以便提高简单脚本的编写效率。 !!! tip 欢迎 ❤️ 欢迎 任何 PR -!!! done idea +!!! tip idea We aim to implement the **built-in function of python in `C#`** and **direct use in `C#`** to improve the effect. - !!! done **Welcome** ❤️ + !!! tip **Welcome** ❤️ welcome any pull request ## 1.2. Recent Changelog From 73c70e082bac1fb6ba8c898356bfac3d372952c2 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 13:52:41 +0800 Subject: [PATCH 47/74] CSharpScript --- CSharp.Scripting.codetext.csx | 3 +++ CSharp.Scripting.csx | 22 ++++++++++++++++++++++ README.md | 5 +++++ 3 files changed, 30 insertions(+) create mode 100644 CSharp.Scripting.codetext.csx create mode 100644 CSharp.Scripting.csx diff --git a/CSharp.Scripting.codetext.csx b/CSharp.Scripting.codetext.csx new file mode 100644 index 0000000..6a8548a --- /dev/null +++ b/CSharp.Scripting.codetext.csx @@ -0,0 +1,3 @@ +var a = 1 + 2; +print(a); +return a; \ No newline at end of file diff --git a/CSharp.Scripting.csx b/CSharp.Scripting.csx new file mode 100644 index 0000000..42c7e94 --- /dev/null +++ b/CSharp.Scripting.csx @@ -0,0 +1,22 @@ +#r "nuget: Python.System, *" +#r "nuget: Microsoft.CodeAnalysis.CSharp.Scripting, *" +using Python; +using static Python.System; +using Microsoft.CodeAnalysis.CSharp.Scripting; +using Microsoft.CodeAnalysis.Scripting; +using System.IO; + +Console.WriteLine(@"测试输入输出函数:Directory.GetCurrentDirectory()"); +var res = await CSharpScript.EvaluateAsync("Directory.GetCurrentDirectory()", + ScriptOptions.Default.WithImports("System.IO")); +Console.WriteLine(res); + + +var codeText = File.ReadAllText(@"./CSharp.Scripting.codetext.csx"); +codeText = codeText.Insert(0, "using static Python.System;\r\n"); +var scriptOptions = ScriptOptions.Default + .AddReferences(typeof(Python.System).Assembly); +scriptOptions.AddReferences(typeof(System.Math).Assembly); + +res = await CSharpScript.EvaluateAsync(codeText, scriptOptions); +Console.WriteLine(res); diff --git a/README.md b/README.md index 3afdb8d..813bca1 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,11 @@ ![Nuget](https://img.shields.io/nuget/dt/Python.System?style=for-the-badge) [![GitHub release](https://img.shields.io/github/v/release/heartacker/Python.System?style=for-the-badge)](https://github.com/heartacker/Python.System/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) From 398ec596207705dbc2c894138e501bee3cbc6b7c Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 14 May 2023 13:53:58 +0800 Subject: [PATCH 48/74] Microsoft.CodeAnalysis.CSharp.Scripting --- .vscode/tasks.json | 2 +- Python.System/Python.System.csproj | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 562cc11..5c375f9 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -13,7 +13,7 @@ ], "group": "none", "presentation": { - "reveal": "silent" + "reveal": "always" }, "problemMatcher": "$msCompile" }, diff --git a/Python.System/Python.System.csproj b/Python.System/Python.System.csproj index ab182ff..6ed75a5 100644 --- a/Python.System/Python.System.csproj +++ b/Python.System/Python.System.csproj @@ -23,6 +23,8 @@ + + From 60a1743ae1d364d1aa1015c62ce120e08dd86cb7 Mon Sep 17 00:00:00 2001 From: heartacker Date: Mon, 15 May 2023 08:49:09 +0800 Subject: [PATCH 49/74] =?UTF-8?q?=E7=90=86=E8=A7=A3=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CSharp.Scripting.csx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CSharp.Scripting.csx b/CSharp.Scripting.csx index 42c7e94..b272fa3 100644 --- a/CSharp.Scripting.csx +++ b/CSharp.Scripting.csx @@ -6,9 +6,13 @@ using Microsoft.CodeAnalysis.CSharp.Scripting; using Microsoft.CodeAnalysis.Scripting; using System.IO; +var so = ScriptOptions.Default.WithImports("System.IO"); +so.WithImports("System"); Console.WriteLine(@"测试输入输出函数:Directory.GetCurrentDirectory()"); -var res = await CSharpScript.EvaluateAsync("Directory.GetCurrentDirectory()", - ScriptOptions.Default.WithImports("System.IO")); +var res = await CSharpScript.EvaluateAsync(@" +using System; +Console.WriteLine(10086); +Directory.GetCurrentDirectory()",so);// *if end with ; no return value Console.WriteLine(res); From bc69838fd0a929080a9e85b73b634a4bc8143840 Mon Sep 17 00:00:00 2001 From: heartacker Date: Tue, 16 May 2023 09:16:57 +0800 Subject: [PATCH 50/74] user home --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 68e3d1d..ccb55e7 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "args": [ "exec", // change to your own folder - "C:/Users/heartacker/.dotnet/tools/.store/dotnet-script/1.4.0/dotnet-script/1.4.0/tools/net7.0/any/dotnet-script.dll", + "${userHome}/.dotnet/tools/.store/dotnet-script/1.4.0/dotnet-script/1.4.0/tools/net7.0/any/dotnet-script.dll", "${file}" ], "cwd": "${workspaceRoot}", From 6b4eaf7a0e24833244ad1db30fb2215ed2a11168 Mon Sep 17 00:00:00 2001 From: heartacker Date: Tue, 16 May 2023 13:10:33 +0800 Subject: [PATCH 51/74] NO --- .vscode/tasks.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 5c375f9..fc30c9e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -14,8 +14,7 @@ "group": "none", "presentation": { "reveal": "always" - }, - "problemMatcher": "$msCompile" + } }, { "label": "buildDemo", From 96271477fa0d9cd646bf4813c6d1113bb68a59fb Mon Sep 17 00:00:00 2001 From: heartacker Date: Tue, 16 May 2023 13:10:40 +0800 Subject: [PATCH 52/74] A --- CSharp.Scripting.csx | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/CSharp.Scripting.csx b/CSharp.Scripting.csx index 42c7e94..43779c9 100644 --- a/CSharp.Scripting.csx +++ b/CSharp.Scripting.csx @@ -1,9 +1,13 @@ #r "nuget: Python.System, *" #r "nuget: Microsoft.CodeAnalysis.CSharp.Scripting, *" + using Python; using static Python.System; -using Microsoft.CodeAnalysis.CSharp.Scripting; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Scripting; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Scripting; +using Microsoft.CodeAnalysis.CSharp.Syntax; using System.IO; Console.WriteLine(@"测试输入输出函数:Directory.GetCurrentDirectory()"); @@ -14,9 +18,29 @@ Console.WriteLine(res); var codeText = File.ReadAllText(@"./CSharp.Scripting.codetext.csx"); codeText = codeText.Insert(0, "using static Python.System;\r\n"); +codeText = codeText.Insert(0, "using static Python.System;\r\n"); var scriptOptions = ScriptOptions.Default .AddReferences(typeof(Python.System).Assembly); scriptOptions.AddReferences(typeof(System.Math).Assembly); -res = await CSharpScript.EvaluateAsync(codeText, scriptOptions); -Console.WriteLine(res); +SyntaxTree tree = CSharpSyntaxTree.ParseText(codeText); + +var script = CSharpScript.Create(codeText, scriptOptions); +/* + public ScriptRunner CreateDelegate(CancellationToken cancellationToken = default); + public Task> RunAsync(object globals, CancellationToken cancellationToken); + public Task> RunAsync(object globals = null, Func catchException = null, CancellationToken cancellationToken = default); + public Task> RunFromAsync(ScriptState previousState, CancellationToken cancellationToken); + public Task> RunFromAsync(ScriptState previousState, Func catchException = null, CancellationToken cancellationToken = default); + public Script WithOptions(ScriptOptions options); +*/ +try +{ + res = await script.RunAsync(); + print(res); +} +catch (System.Exception codeError) +{ + print(codeError.Message); + // print(codeError.StackTrace); +} From 889f3cf234259e106313742b0e9bfffe2df2a63f Mon Sep 17 00:00:00 2001 From: heartacker Date: Tue, 16 May 2023 13:15:27 +0800 Subject: [PATCH 53/74] compile --- CSharp.Scripting.csx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CSharp.Scripting.csx b/CSharp.Scripting.csx index 7f4eb0b..fbf2d39 100644 --- a/CSharp.Scripting.csx +++ b/CSharp.Scripting.csx @@ -16,7 +16,7 @@ Console.WriteLine(@"测试输入输出函数:Directory.GetCurrentDirectory()"); var res = await CSharpScript.EvaluateAsync(@" using System; Console.WriteLine(10086); -Directory.GetCurrentDirectory()",so);// *if end with ; no return value +Directory.GetCurrentDirectory()", so);// *if end with ; no return value Console.WriteLine(res); @@ -40,6 +40,7 @@ var script = CSharpScript.Create(codeText, scriptOptions); */ try { + script.Compile(); res = await script.RunAsync(); print(res); } From 4b0ffddef5ea02168c62beac563b3dad5461224a Mon Sep 17 00:00:00 2001 From: heartacker Date: Tue, 16 May 2023 13:53:05 +0800 Subject: [PATCH 54/74] Namespace --- Python.System/Python/help.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Python.System/Python/help.cs b/Python.System/Python/help.cs index d5f9060..c15b089 100644 --- a/Python.System/Python/help.cs +++ b/Python.System/Python/help.cs @@ -76,6 +76,7 @@ public static void help(Type request) sb.AppendLine("================================================================="); sb.AppendLine("Name\t\t" + request.FullName); + sb.AppendLine("NameSpace\t\t\t" + request.Namespace); sb.AppendLine("Assembly\t\t\t" + request.Assembly.FullName); sb.AppendLine(); sb.AppendLine("field:"); From 234d46d60af16a05effbc0d808814f298325ddf4 Mon Sep 17 00:00:00 2001 From: heartacker Date: Tue, 16 May 2023 15:51:49 +0800 Subject: [PATCH 55/74] =?UTF-8?q?=F0=9F=92=A5**breakChange**:rename=20to?= =?UTF-8?q?=20**CScripting**?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 2 +- .vscode/tasks.json | 2 +- CHANGELOG.md | 4 + ...System.Compare.py => CScripting.Compare.py | 2 +- Python.System.Demo.csx => CScripting.Demo.csx | 4 +- Python.System.Demo.dib => CScripting.Demo.dib | 10 +- CScripting.sln | 37 +++++ CScripting/Built-in/Matlab/fft.cs | 29 ++++ CScripting/Built-in/Matlab/matlab.cs | 13 ++ CScripting/Built-in/abs.cs | 92 +++++++++++ CScripting/Built-in/all.cs | 45 ++++++ CScripting/Built-in/any.cs | 44 ++++++ CScripting/Built-in/bin.cs | 54 +++++++ CScripting/Built-in/bytearry.cs | 126 +++++++++++++++ .../Python => CScripting/Built-in}/chr.cs | 9 +- CScripting/Built-in/help.cs | 117 ++++++++++++++ CScripting/Built-in/hex.cs | 73 +++++++++ .../Python => CScripting/Built-in}/oct.cs | 9 +- CScripting/Built-in/ord.cs | 57 +++++++ CScripting/Built-in/print.cs | 84 ++++++++++ CScripting/CScripting.cs | 143 ++++++++++++++++++ CScripting/CScripting.csproj | 49 ++++++ .../S.System.png => CScripting/CScripting.png | Bin .../Engine}/ClassBase.cs | 2 +- .../Engine}/ClassHelper.cs | 2 +- .../Engine}/ExtensionType.cs | 3 +- .../Engine}/ManagedType.cs | 2 +- .../Engine}/OpsHelper.cs | 4 +- .../Engine}/ReflectionPolyfills.cs | 2 +- {Python.System => CScripting}/ObsoleteAttr.cs | 2 +- .../CScriptingDemo.cs | 10 +- .../CScriptingDemo.csproj | 2 +- CScriptingDemo/Properties/launchSettings.json | 8 + CScriptingDemo/usingglobal.cs | 12 ++ .../Built-in/CScriptingTests.cs | 6 +- .../CScriptingTests.csproj | 2 +- .../Usings.cs | 0 CSharp.Scripting.csx | 10 +- Python.System.sln | 37 ----- Python.System/Python.System.csproj | 38 ----- Python.System/Python/abs.cs | 87 ----------- Python.System/Python/all.cs | 40 ----- Python.System/Python/any.cs | 39 ----- Python.System/Python/bin.cs | 49 ------ Python.System/Python/bytearry.cs | 121 --------------- Python.System/Python/help.cs | 109 ------------- Python.System/Python/hex.cs | 68 --------- Python.System/Python/ord.cs | 52 ------- Python.System/Python/print.cs | 79 ---------- Python.System/System.cs | 137 ----------------- .../Properties/launchSettings.json | 8 - README.md | 52 +++---- 52 files changed, 1061 insertions(+), 927 deletions(-) rename Python.System.Compare.py => CScripting.Compare.py (87%) rename Python.System.Demo.csx => CScripting.Demo.csx (81%) rename Python.System.Demo.dib => CScripting.Demo.dib (84%) create mode 100644 CScripting.sln create mode 100644 CScripting/Built-in/Matlab/fft.cs create mode 100644 CScripting/Built-in/Matlab/matlab.cs create mode 100644 CScripting/Built-in/abs.cs create mode 100644 CScripting/Built-in/all.cs create mode 100644 CScripting/Built-in/any.cs create mode 100644 CScripting/Built-in/bin.cs create mode 100644 CScripting/Built-in/bytearry.cs rename {Python.System/Python => CScripting/Built-in}/chr.cs (94%) create mode 100644 CScripting/Built-in/help.cs create mode 100644 CScripting/Built-in/hex.cs rename {Python.System/Python => CScripting/Built-in}/oct.cs (91%) create mode 100644 CScripting/Built-in/ord.cs create mode 100644 CScripting/Built-in/print.cs create mode 100644 CScripting/CScripting.cs create mode 100644 CScripting/CScripting.csproj rename Python.System/S.System.png => CScripting/CScripting.png (100%) rename {Python.System/Runtime => CScripting/Engine}/ClassBase.cs (97%) rename {Python.System/Runtime => CScripting/Engine}/ClassHelper.cs (99%) rename {Python.System/Runtime => CScripting/Engine}/ExtensionType.cs (97%) rename {Python.System/Runtime => CScripting/Engine}/ManagedType.cs (60%) rename {Python.System/Runtime => CScripting/Engine}/OpsHelper.cs (98%) rename {Python.System/Runtime => CScripting/Engine}/ReflectionPolyfills.cs (97%) rename {Python.System => CScripting}/ObsoleteAttr.cs (95%) rename Python.SystemDemo/SystemDemo.cs => CScriptingDemo/CScriptingDemo.cs (70%) rename Python.SystemDemo/Python.SystemDemo.csproj => CScriptingDemo/CScriptingDemo.csproj (81%) create mode 100644 CScriptingDemo/Properties/launchSettings.json create mode 100644 CScriptingDemo/usingglobal.cs rename Python.SystemTests/SystemTests.cs => CScriptingTests/Built-in/CScriptingTests.cs (94%) rename Python.SystemTests/Python.SystemTests.csproj => CScriptingTests/CScriptingTests.csproj (89%) rename {Python.SystemTests => CScriptingTests}/Usings.cs (100%) delete mode 100644 Python.System.sln delete mode 100644 Python.System/Python.System.csproj delete mode 100644 Python.System/Python/abs.cs delete mode 100644 Python.System/Python/all.cs delete mode 100644 Python.System/Python/any.cs delete mode 100644 Python.System/Python/bin.cs delete mode 100644 Python.System/Python/bytearry.cs delete mode 100644 Python.System/Python/help.cs delete mode 100644 Python.System/Python/hex.cs delete mode 100644 Python.System/Python/ord.cs delete mode 100644 Python.System/Python/print.cs delete mode 100644 Python.System/System.cs delete mode 100644 Python.SystemDemo/Properties/launchSettings.json diff --git a/.vscode/launch.json b/.vscode/launch.json index ccb55e7..b3fc1d1 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -32,7 +32,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "buildDemo", - "program": "${workspaceFolder}/Python.SystemDemo/bin/Debug/net7.0-windows/Python.SystemDemo.exe", + "program": "${workspaceFolder}/CScriptingDemo/bin/Debug/net7.0-windows/CScriptingDemo.exe", "requireExactSource": false, "args": [], "cwd": "${workspaceFolder}", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index fc30c9e..26ed5a0 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -22,7 +22,7 @@ "type": "shell", "args": [ "build", - "${workspaceFolder}/Python.SystemDemo/Python.SystemDemo.csproj", + "${workspaceFolder}/CScriptingDemo/CScriptingDemo.csproj", // Ask dotnet build to generate full paths for file names. "/property:GenerateFullPaths=true", // Do not generate summary otherwise it leads to duplicate errors in Problems panel diff --git a/CHANGELOG.md b/CHANGELOG.md index 9005132..42a8082 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ nothing ## released +- version: 0.0.0-preview2023-5-16 + - time: 2023年5月16日 + - log: + 1. 💥**breakChange**:rename to **CScripting** - version: 1.0.5-pre - time: 2023年5月14日 diff --git a/Python.System.Compare.py b/CScripting.Compare.py similarity index 87% rename from Python.System.Compare.py rename to CScripting.Compare.py index 72071e2..db03be1 100644 --- a/Python.System.Compare.py +++ b/CScripting.Compare.py @@ -1,4 +1,4 @@ -#r "nuget: Python.System, *" +#r "nuget: CScripting, *" addr = 0x12345678 diff --git a/Python.System.Demo.csx b/CScripting.Demo.csx similarity index 81% rename from Python.System.Demo.csx rename to CScripting.Demo.csx index 8c6af67..834e488 100644 --- a/Python.System.Demo.csx +++ b/CScripting.Demo.csx @@ -1,5 +1,5 @@ -#r "nuget: Python.System, *" -using static Python.System; +#r "nuget: CScripting, *" +using static CScripting; var addr = 0x12345678; var addrr = hex(addr); diff --git a/Python.System.Demo.dib b/CScripting.Demo.dib similarity index 84% rename from Python.System.Demo.dib rename to CScripting.Demo.dib index 5cff10b..f810359 100644 --- a/Python.System.Demo.dib +++ b/CScripting.Demo.dib @@ -4,9 +4,9 @@ #!markdown -## Python.System +## CScripting -demo of Python.System +demo of CScripting #!markdown @@ -15,15 +15,15 @@ demo of Python.System #!csharp -#r "nuget: Python.System, *" +#r "nuget: CScripting, *" #!markdown -- using the static functions in `Python.System` +- using the static functions in `CScripting` #!csharp -using static Python.System; +using static CScripting; #!markdown diff --git a/CScripting.sln b/CScripting.sln new file mode 100644 index 0000000..ece747a --- /dev/null +++ b/CScripting.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33627.172 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CScripting", "CScripting\CScripting.csproj", "{9DF9921F-4A9E-4EE3-908D-2BCC79D24BE6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CScriptingDemo", "CScriptingDemo\CScriptingDemo.csproj", "{FFC71AD4-85B0-4050-8ED0-BAD84413CFA6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CScriptingTests", "CScriptingTests\CScriptingTests.csproj", "{656D583E-E1A1-4127-86F4-F0A8265B2B03}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9DF9921F-4A9E-4EE3-908D-2BCC79D24BE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9DF9921F-4A9E-4EE3-908D-2BCC79D24BE6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9DF9921F-4A9E-4EE3-908D-2BCC79D24BE6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9DF9921F-4A9E-4EE3-908D-2BCC79D24BE6}.Release|Any CPU.Build.0 = Release|Any CPU + {FFC71AD4-85B0-4050-8ED0-BAD84413CFA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FFC71AD4-85B0-4050-8ED0-BAD84413CFA6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FFC71AD4-85B0-4050-8ED0-BAD84413CFA6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FFC71AD4-85B0-4050-8ED0-BAD84413CFA6}.Release|Any CPU.Build.0 = Release|Any CPU + {656D583E-E1A1-4127-86F4-F0A8265B2B03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {656D583E-E1A1-4127-86F4-F0A8265B2B03}.Debug|Any CPU.Build.0 = Debug|Any CPU + {656D583E-E1A1-4127-86F4-F0A8265B2B03}.Release|Any CPU.ActiveCfg = Release|Any CPU + {656D583E-E1A1-4127-86F4-F0A8265B2B03}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {19598AB3-02E0-4316-A003-BDCAC338A7DA} + EndGlobalSection +EndGlobal diff --git a/CScripting/Built-in/Matlab/fft.cs b/CScripting/Built-in/Matlab/fft.cs new file mode 100644 index 0000000..046b0c9 --- /dev/null +++ b/CScripting/Built-in/Matlab/fft.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Numerics; +using System.Text; + +#if WITH_NAME_SPACE +namespace CScripting +{ +#endif +#if !MATLAB_NOT_IN_TOP_NAMESPACE +public partial class CScripting +{ +#endif + public partial class matlab + { + public static Complex fft(object arg1, object arg2, object arg3) + { + + throw new NotImplementedException(); + } + } +#if !MATLAB_NOT_IN_TOP_NAMESPACE +} +#endif + + +#if WITH_NAME_SPACE +} +#endif diff --git a/CScripting/Built-in/Matlab/matlab.cs b/CScripting/Built-in/Matlab/matlab.cs new file mode 100644 index 0000000..e8fc5dd --- /dev/null +++ b/CScripting/Built-in/Matlab/matlab.cs @@ -0,0 +1,13 @@ +using System; +using System.Numerics; + +public partial class CScripting +{ + public partial class matlab + { + public static int[] linespace(int start, int end, int step = 1) + { + return new int[end - start]; + } + } +} \ No newline at end of file diff --git a/CScripting/Built-in/abs.cs b/CScripting/Built-in/abs.cs new file mode 100644 index 0000000..a5109e9 --- /dev/null +++ b/CScripting/Built-in/abs.cs @@ -0,0 +1,92 @@ +using System; +using System.Numerics; + +#if WITH_NAME_SPACE +namespace CScripting +{ +#endif + +public partial class CScripting +{ + #region abs + //public const double e = Math.E; + public const double pi = Math.PI; + + /// + /// 将复数转为绝对值 + /// + /// + /// + public static double Abs(Complex num) => Abs(num.Magnitude); + + /// + public static decimal Abs(decimal value) => Abs(value); + + /// + public static double Abs(double value) => Abs(value); + + /// + public static short Abs(short value) => Abs(value); + + /// + public static int Abs(int value) => Abs(value); + + /// + public static long Abs(long value) => Abs(value); + + /// + public static sbyte Abs(sbyte value) => Abs(value); + + /// + public static float Abs(float value) => Abs(value); + + + + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `Abs` instead.")] +#endif + public static double abs(Complex num) => Math.Abs(num.Magnitude); + +#if OBSOLETE + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif + public static double abs(double num) => Math.Abs(num); + +#if OBSOLETE + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif + public static decimal abs(decimal num) => Math.Abs(num); + +#if OBSOLETE + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif + public static short abs(short num) => Math.Abs(num); + +#if OBSOLETE + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif + public static int abs(int num) => Math.Abs(num); +#if OBSOLETE + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif + public static long abs(long num) => Math.Abs(num); +#if OBSOLETE + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif + public static sbyte abs(sbyte num) => Math.Abs(num); + +#if OBSOLETE + [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] +#endif + public static float abs(float num) => Math.Abs(num); + + #endregion + +} +#if WITH_NAME_SPACE +} +#endif diff --git a/CScripting/Built-in/all.cs b/CScripting/Built-in/all.cs new file mode 100644 index 0000000..9d4230e --- /dev/null +++ b/CScripting/Built-in/all.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; + +#if WITH_NAME_SPACE +namespace CScripting +{ +#endif + +public partial class CScripting +{ + #region all + /// + /// + /// + /// + /// + /// + /// + public static bool All(IEnumerable iterable, Func predicate = null) + => All(iterable, predicate); + + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(All)}` instead.")] +#endif + public static bool all(IEnumerable iterable, Func predicate = null) + { + if (predicate == null) + return iterable.All(a => Convert.ToBoolean(a)); + else + return iterable.All(predicate); + } + + + #endregion + +} +#if WITH_NAME_SPACE +} +#endif \ No newline at end of file diff --git a/CScripting/Built-in/any.cs b/CScripting/Built-in/any.cs new file mode 100644 index 0000000..7e98b23 --- /dev/null +++ b/CScripting/Built-in/any.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; + +#if WITH_NAME_SPACE +namespace CScripting +{ +#endif + +public partial class CScripting +{ + #region any + /// + /// + /// + /// + /// + /// + /// + public static bool Any(IEnumerable iterable, Func predicate = null) + => Any(iterable, predicate); + + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Any)}` instead.")] +#endif + public static bool any(IEnumerable iterable, Func predicate = null) + { + if (predicate == null) + return iterable.Any(); + else + return iterable.Any(predicate); + } + + #endregion + +} +#if WITH_NAME_SPACE +} +#endif \ No newline at end of file diff --git a/CScripting/Built-in/bin.cs b/CScripting/Built-in/bin.cs new file mode 100644 index 0000000..a93d147 --- /dev/null +++ b/CScripting/Built-in/bin.cs @@ -0,0 +1,54 @@ +using System; + +#if WITH_NAME_SPACE +namespace CScripting +{ +#endif + +public partial class CScripting +{ + #region bin + + /// + /// 将整形的数转为二进制 + /// + /// 整数 + /// 位宽, 则不关注,如果转换结果大于位宽,则取位宽 + /// 二进制字符串 + public static string Bin(long x, int? width = null) + => Bin(x, width); + + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(bin)}` instead.")] +#endif + public static string bin(long x, int? width = null) + { + if (width == null || width <= 0) + { + return "0b" + Convert.ToString(x, 2); + } + else + { + string format = Convert.ToString(x, 2); + if (format.Length < width) + { + string par = ""; + for (int c = 0; c < width - format.Length; c++) + { + par += "0"; + } + return "0b" + par + format; + } + return "0b" + format; + } + } + + #endregion +} +#if WITH_NAME_SPACE +} +#endif \ No newline at end of file diff --git a/CScripting/Built-in/bytearry.cs b/CScripting/Built-in/bytearry.cs new file mode 100644 index 0000000..ee5944c --- /dev/null +++ b/CScripting/Built-in/bytearry.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using System.Text; + +#if WITH_NAME_SPACE +namespace CScripting +{ +#endif + +public partial class CScripting +{ + #region bytes + + + public static byte[] Bytes(string source, string encoding = "utf-8", string errors = "strict") + => bytes(source, encoding, errors); + /// + /// 仅支持byte sbyte int uint ushort short 数组 + /// + /// + /// + public static byte[] Bytes(IEnumerable source) => bytes(source); + public static byte[] Bytes(uint source) => bytes(source); + public static byte[] Bytes(int source) => bytes(source); + + + + + + + public static byte[] bytes(string source, string encoding = "utf-8", string errors = "strict") + => bytearray(source, encoding, errors); + /// + /// 仅支持byte sbyte int uint ushort short 数组 + /// + /// + /// + public static byte[] bytes(IEnumerable source) => bytearray(source); + public static byte[] bytes(uint source) => bytearray(source); + public static byte[] bytes(int source) => bytearray(source); + + + + #endregion + + + #region bytearry + + + public static byte[] Bytearray(string source, string encoding = "utf-8", string errors = "strict") + => bytearray(source, encoding, errors); + + public static byte[] Bytearray(uint source) => bytearray(source); + public static byte[] Bytearray(int source) => bytearray((uint)source); + + /// + /// 仅支持byte sbyte int uint ushort short 数组 + /// + /// + /// + /// + public static byte[] Bytearray(IEnumerable source) => bytearray(source); + + + + + + + public static byte[] bytearray(string source, string encoding = "utf-8", string errors = "strict") + { + return Encoding.GetEncoding(encoding, new EncoderExceptionFallback(), new DecoderExceptionFallback()).GetBytes(source); + } + + public static byte[] bytearray(uint source) => new byte[source]; + public static byte[] bytearray(int source) => bytearray((uint)source); + + /// + /// 仅支持byte sbyte int uint ushort short 数组 + /// + /// + /// + /// + public static byte[] bytearray(IEnumerable source) + { + if (source is IEnumerable bytei) + { + byte[] byteArray = bytei.ToArray(); + return byteArray; + } + else if (source is IEnumerable sbytei) + { + byte[] byteArray = sbytei.Select(i => (byte)i).ToArray(); + return byteArray; + } + else if (source is IEnumerable shorti) + { + byte[] byteArray = shorti.Select(i => (byte)i).ToArray(); + return byteArray; + } + else if (source is IEnumerable ushorti) + { + byte[] byteArray = ushorti.Select(i => (byte)i).ToArray(); + return byteArray; + } + else if (source is IEnumerable inti) + { + byte[] byteArray = inti.Select(i => (byte)i).ToArray(); + return byteArray; + } + else if (source is IEnumerable uinti) + { + byte[] byteArray = uinti.Select(i => (byte)i).ToArray(); + return byteArray; + } + else + { + throw new ArgumentException("source parameter must be an integer, a string, or an iterable object of integers or bytes"); + } + } + #endregion +} +#if WITH_NAME_SPACE +} +#endif \ No newline at end of file diff --git a/Python.System/Python/chr.cs b/CScripting/Built-in/chr.cs similarity index 94% rename from Python.System/Python/chr.cs rename to CScripting/Built-in/chr.cs index 9a8870f..80f3fe4 100644 --- a/Python.System/Python/chr.cs +++ b/CScripting/Built-in/chr.cs @@ -1,8 +1,11 @@ using System; -namespace Python +#if WITH_NAME_SPACE +namespace CScripting { - public partial class System +#endif + +public partial class CScripting { #region chr public static string Chr(uint i) => chr(i); @@ -57,4 +60,6 @@ public static string chr(int i) #endregion } +#if WITH_NAME_SPACE } +#endif diff --git a/CScripting/Built-in/help.cs b/CScripting/Built-in/help.cs new file mode 100644 index 0000000..8f6af32 --- /dev/null +++ b/CScripting/Built-in/help.cs @@ -0,0 +1,117 @@ +using System; +using System.Text; +using System.Collections.Generic; + +#if WITH_NAME_SPACE +namespace CScripting +{ +#endif + +using CScriptingEngine; +using static CScripting; + +public partial class CScripting +{ + public static void Help() + { + + } + + + + /// + /// 启动内置的帮助系统(此函数主要在交互式中使用)。 + /// 如果实参是一个字符串,则在模块、函数、类、方法、关键字或文档主题中搜索该字符串,并在控制台上打印帮助信息。 + /// 如果实参是其他任意对象,则会生成该对象的帮助页。 + /// + /// + /// + public static void Help(object request) => help(request.GetType()); + + /// + /// 启动内置的帮助系统(此函数主要在交互式中使用)。 + /// 如果实参是一个字符串,则在模块、函数、类、方法、关键字或文档主题中搜索该字符串,并在控制台上打印帮助信息。 + /// 如果实参是其他任意对象,则会生成该对象的帮助页。 + /// + /// + /// + + public static void Help(Type request) => help(request); + + + + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] +#endif + public static void help() + { + print("Welcome to the CScripting, Welcome PRs => https://github.com/heartacker/CScripting"); + } + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] +#endif + public static void help(object request) => help(request.GetType()); + + + // //如果没有实参,解释器控制台里会启动交互式帮助系统。 + + /// + /// 启动内置的帮助系统(此函数主要在交互式中使用)。 + /// 如果实参是一个字符串,则在模块、函数、类、方法、关键字或文档主题中搜索该字符串,并在控制台上打印帮助信息。 + /// 如果实参是其他任意对象,则会生成该对象的帮助页。 + /// + /// + /// + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] +#endif + public static void help(Type request) + { + ClassHelper.ClassInfo c = ClassHelper.GetClassInfo(request); + var sb = new StringBuilder(); + + sb.AppendLine("================================================================="); + + sb.AppendLine("Name\t\t" + request.FullName); + sb.AppendLine("NameSpace\t\t\t" + request.Namespace); + sb.AppendLine("Assembly\t\t\t" + request.Assembly.FullName); + sb.AppendLine(); + sb.AppendLine("field:"); + sb.AppendLine("----------------------------------------------------------------"); + + foreach (var item in c.members) + { + if (item.Value is FieldObject) + { + sb.AppendLine($"{item.Key}:\t\t\t{((FieldObject)item.Value).fi}"); + } + } + sb.AppendLine(); + sb.AppendLine("Method:"); + sb.AppendLine("----------------------------------------------------------------"); + + foreach (var item in c.members) + { + if (item.Value is MethodObject) + { + sb.AppendLine($"{item.Key}:\t\t\t{((MethodObject)item.Value).mlist[0].ToString()}"); + } + } + sb.AppendLine(); + sb.AppendLine("================================================================="); + sb.AppendLine(); + Console.Write(sb.ToString()); + } +} + +#if WITH_NAME_SPACE +} +#endif \ No newline at end of file diff --git a/CScripting/Built-in/hex.cs b/CScripting/Built-in/hex.cs new file mode 100644 index 0000000..08c7f2d --- /dev/null +++ b/CScripting/Built-in/hex.cs @@ -0,0 +1,73 @@ +using System; +using System.Numerics; + +#if WITH_NAME_SPACE +namespace CScripting +{ +#endif + +public partial class CScripting +{ + #region hex + /// + /// 将整形的数转为hex + /// + /// 整数 + /// 位宽, 则不关注,如果转换结果大于位宽,则取位宽 + /// hex字符串 + public static string Hex(long x, int? width = null) + => Hex(x, width); + + /// + /// 将ulong整形的数转为hex + /// + /// 整数 + /// 位宽, 则不关注,如果转换结果大于位宽,则取位宽 + /// hex字符串 + + public static string Hex(ulong x, int? width = null) + => Hex(x, width); + + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Hex)}` instead.")] +#endif + public static string hex(long x, int? width = null) + { + if (width == null || width <= 0) + { + return string.Format("0x{0:X}", x); + } + else + { + string format = "0x{0:" + "X" + width + "}"; + return string.Format(format, x); + } + } + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Hex)}` instead.")] +#endif + public static string hex(ulong x, int? width = null) + { + if (width == null || width <= 0) + { + return string.Format("0x{0:X}", x); + } + else + { + string format = "0x{0:" + "X" + width + "}"; + return string.Format(format, x); + } + } + + #endregion + +} +#if WITH_NAME_SPACE +} +#endif \ No newline at end of file diff --git a/Python.System/Python/oct.cs b/CScripting/Built-in/oct.cs similarity index 91% rename from Python.System/Python/oct.cs rename to CScripting/Built-in/oct.cs index e41b0e1..3e7f54f 100644 --- a/Python.System/Python/oct.cs +++ b/CScripting/Built-in/oct.cs @@ -1,8 +1,11 @@ using System; -namespace Python +#if WITH_NAME_SPACE +namespace CScripting { - public partial class System +#endif + +public partial class CScripting { #region oct public static string Oct(long x, int? width = null) @@ -46,4 +49,6 @@ public static string oct(long x, int? width = null) #endregion } +#if WITH_NAME_SPACE } +#endif diff --git a/CScripting/Built-in/ord.cs b/CScripting/Built-in/ord.cs new file mode 100644 index 0000000..b25aa05 --- /dev/null +++ b/CScripting/Built-in/ord.cs @@ -0,0 +1,57 @@ +using System; + +#if WITH_NAME_SPACE +namespace CScripting +{ +#endif + +public partial class CScripting +{ + #region ord + + public static int Ord(char c) => ord(c); + + + + /// + /// 对表示单个 Unicode 字符的字符串,返回代表它 Unicode 码点的整数。例如 ord('a') 返回整数 97, ord('€') (欧元符号)返回 8364 。这是 chr() 的逆函数。 + /// + /// + /// + /// + public static int Ord(string c) => ord(c); + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Ord)}` instead.")] +#endif + public static int ord(char c) => Convert.ToInt32(c); + + + + /// + /// 对表示单个 Unicode 字符的字符串,返回代表它 Unicode 码点的整数。例如 ord('a') 返回整数 97, ord('€') (欧元符号)返回 8364 。这是 chr() 的逆函数。 + /// + /// + /// + /// + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Ord)}` instead.")] +#endif + public static int ord(string c) + { + if (string.IsNullOrEmpty(c) || c.Length != 1) + { + throw new ArgumentException("实参必须是表示单个 Unicode 字符的字符串"); + } + return Convert.ToInt32(c[0]); + } + #endregion + +} +#if WITH_NAME_SPACE +} +#endif \ No newline at end of file diff --git a/CScripting/Built-in/print.cs b/CScripting/Built-in/print.cs new file mode 100644 index 0000000..fc2130d --- /dev/null +++ b/CScripting/Built-in/print.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections; +using System.IO; +using System.Numerics; + +#if WITH_NAME_SPACE +namespace CScripting +{ +#endif + +public partial class CScripting +{ + #region print + + public static void Print(object @object, + string sep = " ", + string end = "\r\n", + StreamWriter file = null, + bool flush = false) => print(@object, sep, end, file, flush); + + + public static void Print(IEnumerable @object, + string sep = " ", + string end = "\r\n", + StreamWriter file = null, + bool flush = false) => print(@object, sep, end, file, flush); + + + + + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] +#endif + public static void print(object @object, + string sep = " ", + string end = "\r\n", + StreamWriter file = null, + bool flush = false) + { + var _file = file ?? Console.Out; + + _file.Write(@object); + _file.Write(end); + if (flush) _file.Flush(); + } + +#if OBSOLETE + [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] +#endif + public static void print(IEnumerable @object, + string sep = " ", + string end = "\r\n", + StreamWriter file = null, + bool flush = false) + { + var _file = file ?? Console.Out; + if (@object is String) + { + _file.Write(@object); + _file.Write(end); + } + else + { + string str = ""; + foreach (var item in @object) + { + str += item.ToString(); + str += sep; + } + + str = str.Remove(str.Length - sep.Length, sep.Length); + + _file.Write(str); + _file.Write(end); + } + if (flush) _file.Flush(); + } + #endregion + +} +#if WITH_NAME_SPACE +} +#endif \ No newline at end of file diff --git a/CScripting/CScripting.cs b/CScripting/CScripting.cs new file mode 100644 index 0000000..9996414 --- /dev/null +++ b/CScripting/CScripting.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections; +using System.IO; +using System.Linq; +using System.Numerics; +using System.Collections.Generic; +//https://ww2.mathworks.cn/help/matlab/referencelist.html?type=function&listtype=cat&category=language-fundamentals&blocktype=all&capability= + +using static System.Math; +using static System.Linq.Enumerable; +using static System.Numerics.Complex; +using static System.Numerics.BigInteger; + +#if false +using ObsoleteAttribute = System.ObsoleteAttribute; +#else +using ObsoleteAttribute = CScriptingEngine.Attr.ObsoleteAttribute; +#endif + +#if WITH_NAME_SPACE +namespace CScripting +{ +#endif + +/// +/// A: +/// abs() +/// aiter() // x +/// all() +/// any() +/// anext() +/// ascii() +/// +/// B: +/// bin() +/// bool() +/// breakpoint() +/// bytearray() +/// bytes() +/// +/// C: +/// callable() +/// chr() +/// classmethod() +/// compile() +/// complex() +/// +/// D: +/// delattr() +/// dict() +/// dir() +/// divmod() +/// +/// E: +/// enumerate() +/// eval() +/// exec() +/// +/// F: +/// filter() +/// float() +/// format() +/// frozenset() +/// +/// G: +/// getattr() +/// globals() +/// +/// H: +/// hasattr() +/// hash() +/// help() +/// hex() +/// +/// I: +/// id() +/// input() +/// int() +/// isinstance() +/// issubclass() +/// iter() +/// +/// L: +/// len() +/// list() +/// locals() +/// +/// M: +/// map() +/// max() +/// memoryview() +/// min() +/// +/// N: +/// next() +/// +/// O: +/// object() +/// oct() +/// open() +/// ord() +/// +/// P: +/// pow() +/// print() +/// property() +/// +/// R: +/// range() +/// repr() +/// reversed() +/// round() +/// +/// S: +/// set() +/// setattr() +/// slice() +/// sorted() +/// staticmethod() +/// str() +/// sum() +/// super() +/// +/// T: +/// tuple() +/// type() +/// +/// V: +/// vars() +/// +/// Z: +/// zip() +/// +/// _ +/// __import__() +/// +public partial class CScripting +{ +} + +#if WITH_NAME_SPACE +} +#endif diff --git a/CScripting/CScripting.csproj b/CScripting/CScripting.csproj new file mode 100644 index 0000000..71bf177 --- /dev/null +++ b/CScripting/CScripting.csproj @@ -0,0 +1,49 @@ + + + + netstandard2.0 + Library + disable + disable + True + CScripting: CSharp Static System function Like Python + heartacker + + provide some static funtion that like python and write c# some like Python + + see https://github.com/heartacker/CScripting.git + + MIT + + CScripting.png + https://github.com/heartacker/CScripting.git + git + static;python;function;script;CScripting;csharpscript;matlab;cli + see https://github.com/heartacker/CScripting/blob/master/CHANGELOG.md + 0.0.1-preview2023-5-16 + CScripting + $(MSBuildProjectName) + README.md + + + + + True + \ + + + + + + + + + + + + True + \ + + + + \ No newline at end of file diff --git a/Python.System/S.System.png b/CScripting/CScripting.png similarity index 100% rename from Python.System/S.System.png rename to CScripting/CScripting.png diff --git a/Python.System/Runtime/ClassBase.cs b/CScripting/Engine/ClassBase.cs similarity index 97% rename from Python.System/Runtime/ClassBase.cs rename to CScripting/Engine/ClassBase.cs index 0ffb54f..4e9467f 100644 --- a/Python.System/Runtime/ClassBase.cs +++ b/CScripting/Engine/ClassBase.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Runtime.Serialization; -namespace Python +namespace CScriptingEngine { internal class ClassBase : ManagedType, IDeserializationCallback { diff --git a/Python.System/Runtime/ClassHelper.cs b/CScripting/Engine/ClassHelper.cs similarity index 99% rename from Python.System/Runtime/ClassHelper.cs rename to CScripting/Engine/ClassHelper.cs index a396f62..d740fa1 100644 --- a/Python.System/Runtime/ClassHelper.cs +++ b/CScripting/Engine/ClassHelper.cs @@ -7,7 +7,7 @@ using System.Text; -namespace Python +namespace CScriptingEngine { public static class ClassHelper { diff --git a/Python.System/Runtime/ExtensionType.cs b/CScripting/Engine/ExtensionType.cs similarity index 97% rename from Python.System/Runtime/ExtensionType.cs rename to CScripting/Engine/ExtensionType.cs index f198e50..a88e354 100644 --- a/Python.System/Runtime/ExtensionType.cs +++ b/CScripting/Engine/ExtensionType.cs @@ -1,9 +1,8 @@ using System; using System.Reflection; -using System = System; -namespace Python +namespace CScriptingEngine { internal class ExtensionType { diff --git a/Python.System/Runtime/ManagedType.cs b/CScripting/Engine/ManagedType.cs similarity index 60% rename from Python.System/Runtime/ManagedType.cs rename to CScripting/Engine/ManagedType.cs index 2b4116b..341778a 100644 --- a/Python.System/Runtime/ManagedType.cs +++ b/CScripting/Engine/ManagedType.cs @@ -1,4 +1,4 @@ -namespace Python +namespace CScriptingEngine { internal class ManagedType { diff --git a/Python.System/Runtime/OpsHelper.cs b/CScripting/Engine/OpsHelper.cs similarity index 98% rename from Python.System/Runtime/OpsHelper.cs rename to CScripting/Engine/OpsHelper.cs index c013561..fdfcac7 100644 --- a/Python.System/Runtime/OpsHelper.cs +++ b/CScripting/Engine/OpsHelper.cs @@ -4,9 +4,9 @@ using System.Linq.Expressions; using System.Reflection; -using static Python.OpsHelper; +using static CScriptingEngine.OpsHelper; -namespace Python +namespace CScriptingEngine { internal static class OpsHelper { diff --git a/Python.System/Runtime/ReflectionPolyfills.cs b/CScripting/Engine/ReflectionPolyfills.cs similarity index 97% rename from Python.System/Runtime/ReflectionPolyfills.cs rename to CScripting/Engine/ReflectionPolyfills.cs index d19974b..2695f0b 100644 --- a/Python.System/Runtime/ReflectionPolyfills.cs +++ b/CScripting/Engine/ReflectionPolyfills.cs @@ -5,7 +5,7 @@ using System.Reflection; using System.Reflection.Emit; -namespace Python +namespace CScriptingEngine { internal static class ReflectionPolyfills { diff --git a/Python.System/ObsoleteAttr.cs b/CScripting/ObsoleteAttr.cs similarity index 95% rename from Python.System/ObsoleteAttr.cs rename to CScripting/ObsoleteAttr.cs index c9ec807..f1f0092 100644 --- a/Python.System/ObsoleteAttr.cs +++ b/CScripting/ObsoleteAttr.cs @@ -1,6 +1,6 @@ using System; -namespace Python.Attr +namespace CScriptingEngine.Attr { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | diff --git a/Python.SystemDemo/SystemDemo.cs b/CScriptingDemo/CScriptingDemo.cs similarity index 70% rename from Python.SystemDemo/SystemDemo.cs rename to CScriptingDemo/CScriptingDemo.cs index b669383..205d52c 100644 --- a/Python.SystemDemo/SystemDemo.cs +++ b/CScriptingDemo/CScriptingDemo.cs @@ -1,7 +1,7 @@ -using static Python.System; - -namespace Python.SystemDemo +namespace CScriptingDemo { + using static CScripting; + public class Demo { public static void Main(string[] args) @@ -21,7 +21,9 @@ public static void Main(string[] args) help(a); help(typeof(Math)); - help(typeof(Python.System)); + help(typeof(CScripting)); + help(typeof(matlab)); + help(typeof(CScripting.matlab)); } } diff --git a/Python.SystemDemo/Python.SystemDemo.csproj b/CScriptingDemo/CScriptingDemo.csproj similarity index 81% rename from Python.SystemDemo/Python.SystemDemo.csproj rename to CScriptingDemo/CScriptingDemo.csproj index 630602d..e7f9154 100644 --- a/Python.SystemDemo/Python.SystemDemo.csproj +++ b/CScriptingDemo/CScriptingDemo.csproj @@ -12,7 +12,7 @@ - + diff --git a/CScriptingDemo/Properties/launchSettings.json b/CScriptingDemo/Properties/launchSettings.json new file mode 100644 index 0000000..74d38eb --- /dev/null +++ b/CScriptingDemo/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "CScriptingDemo": { + "commandName": "Project", + "commandLineArgs": "Hello CScripting" + } + } +} \ No newline at end of file diff --git a/CScriptingDemo/usingglobal.cs b/CScriptingDemo/usingglobal.cs new file mode 100644 index 0000000..38be5e9 --- /dev/null +++ b/CScriptingDemo/usingglobal.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static global::CScripting; +namespace CScriptingDemo +{ + internal class usingglobal + { + } +} diff --git a/Python.SystemTests/SystemTests.cs b/CScriptingTests/Built-in/CScriptingTests.cs similarity index 94% rename from Python.SystemTests/SystemTests.cs rename to CScriptingTests/Built-in/CScriptingTests.cs index 9bfd276..769ac94 100644 --- a/Python.SystemTests/SystemTests.cs +++ b/CScriptingTests/Built-in/CScriptingTests.cs @@ -5,12 +5,12 @@ using System.Text; using System.Threading.Tasks; -using static Python.System; +using static CScripting; -namespace Python.Tests +namespace Tests { [TestClass()] - public class SystemTests + public class CScriptingTests { [TestMethod()] [DataRow(10, "0xA")] diff --git a/Python.SystemTests/Python.SystemTests.csproj b/CScriptingTests/CScriptingTests.csproj similarity index 89% rename from Python.SystemTests/Python.SystemTests.csproj rename to CScriptingTests/CScriptingTests.csproj index ab52d65..52d0b33 100644 --- a/Python.SystemTests/Python.SystemTests.csproj +++ b/CScriptingTests/CScriptingTests.csproj @@ -17,7 +17,7 @@ - + diff --git a/Python.SystemTests/Usings.cs b/CScriptingTests/Usings.cs similarity index 100% rename from Python.SystemTests/Usings.cs rename to CScriptingTests/Usings.cs diff --git a/CSharp.Scripting.csx b/CSharp.Scripting.csx index fbf2d39..798fc0e 100644 --- a/CSharp.Scripting.csx +++ b/CSharp.Scripting.csx @@ -1,8 +1,8 @@ -#r "nuget: Python.System, *" +#r "nuget: CScripting, *" #r "nuget: Microsoft.CodeAnalysis.CSharp.Scripting, *" using Python; -using static Python.System; +using static CScripting; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Scripting; using Microsoft.CodeAnalysis.CSharp; @@ -21,10 +21,10 @@ Console.WriteLine(res); var codeText = File.ReadAllText(@"./CSharp.Scripting.codetext.csx"); -codeText = codeText.Insert(0, "using static Python.System;\r\n"); -codeText = codeText.Insert(0, "using static Python.System;\r\n"); +codeText = codeText.Insert(0, "using static CScripting;\r\n"); +codeText = codeText.Insert(0, "using static CScripting;\r\n"); var scriptOptions = ScriptOptions.Default - .AddReferences(typeof(Python.System).Assembly); + .AddReferences(typeof(CScripting).Assembly); scriptOptions.AddReferences(typeof(System.Math).Assembly); SyntaxTree tree = CSharpSyntaxTree.ParseText(codeText); diff --git a/Python.System.sln b/Python.System.sln deleted file mode 100644 index 68eab8b..0000000 --- a/Python.System.sln +++ /dev/null @@ -1,37 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.5.33627.172 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.System", "Python.System\Python.System.csproj", "{CAAA3827-188E-49E5-9293-5708EEC891BF}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.SystemDemo", "Python.SystemDemo\Python.SystemDemo.csproj", "{86746963-6158-4728-B19A-AC6D78C8486F}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Python.SystemTests", "Python.SystemTests\Python.SystemTests.csproj", "{5D183A65-E961-4B9F-9365-1BA794005A64}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CAAA3827-188E-49E5-9293-5708EEC891BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CAAA3827-188E-49E5-9293-5708EEC891BF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CAAA3827-188E-49E5-9293-5708EEC891BF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CAAA3827-188E-49E5-9293-5708EEC891BF}.Release|Any CPU.Build.0 = Release|Any CPU - {86746963-6158-4728-B19A-AC6D78C8486F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {86746963-6158-4728-B19A-AC6D78C8486F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {86746963-6158-4728-B19A-AC6D78C8486F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {86746963-6158-4728-B19A-AC6D78C8486F}.Release|Any CPU.Build.0 = Release|Any CPU - {5D183A65-E961-4B9F-9365-1BA794005A64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5D183A65-E961-4B9F-9365-1BA794005A64}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5D183A65-E961-4B9F-9365-1BA794005A64}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5D183A65-E961-4B9F-9365-1BA794005A64}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {19598AB3-02E0-4316-A003-BDCAC338A7DA} - EndGlobalSection -EndGlobal diff --git a/Python.System/Python.System.csproj b/Python.System/Python.System.csproj deleted file mode 100644 index 6ed75a5..0000000 --- a/Python.System/Python.System.csproj +++ /dev/null @@ -1,38 +0,0 @@ - - - - netstandard2.0 - Library - disable - disable - True - Static System function Like Python - heartacker - provide some static funtion that like python and write c# some like Python - see https://github.com/heartacker/Static.System.git - - MIT - - S.System.png - https://github.com/heartacker/Static.System.git - git - static;python;function;script; - see https://github.com/heartacker/Python.System/blob/master/CHANGELOG.md - 0.0.0.2 - 1.0.7 - - - - - - - - - - - True - \ - - - - \ No newline at end of file diff --git a/Python.System/Python/abs.cs b/Python.System/Python/abs.cs deleted file mode 100644 index a1b7691..0000000 --- a/Python.System/Python/abs.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Numerics; - -namespace Python -{ - public partial class System - { - #region abs - //public const double e = Math.E; - public const double pi = Math.PI; - - /// - /// 将复数转为绝对值 - /// - /// - /// - public static double Abs(Complex num) => Abs(num.Magnitude); - - /// - public static decimal Abs(decimal value) => Abs(value); - - /// - public static double Abs(double value) => Abs(value); - - /// - public static short Abs(short value) => Abs(value); - - /// - public static int Abs(int value) => Abs(value); - - /// - public static long Abs(long value) => Abs(value); - - /// - public static sbyte Abs(sbyte value) => Abs(value); - - /// - public static float Abs(float value) => Abs(value); - - - - - - - -#if OBSOLETE - [Obsolete("This method is deprecated, use `Abs` instead.")] -#endif - public static double abs(Complex num) => Math.Abs(num.Magnitude); - -#if OBSOLETE - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] -#endif - public static double abs(double num) => Math.Abs(num); - -#if OBSOLETE - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] -#endif - public static decimal abs(decimal num) => Math.Abs(num); - -#if OBSOLETE - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] -#endif - public static short abs(short num) => Math.Abs(num); - -#if OBSOLETE - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] -#endif - public static int abs(int num) => Math.Abs(num); -#if OBSOLETE - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] -#endif - public static long abs(long num) => Math.Abs(num); -#if OBSOLETE - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] -#endif - public static sbyte abs(sbyte num) => Math.Abs(num); - -#if OBSOLETE - [Obsolete("This method is deprecated, `using static System.Math;` and use `Abs` instead.")] -#endif - public static float abs(float num) => Math.Abs(num); - - #endregion - - } -} diff --git a/Python.System/Python/all.cs b/Python.System/Python/all.cs deleted file mode 100644 index 90e4920..0000000 --- a/Python.System/Python/all.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; - -namespace Python -{ - public partial class System - { - #region all - /// - /// - /// - /// - /// - /// - /// - public static bool All(IEnumerable iterable, Func predicate = null) - => All(iterable, predicate); - - - - - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(All)}` instead.")] -#endif - public static bool all(IEnumerable iterable, Func predicate = null) - { - if (predicate == null) - return iterable.All(a => Convert.ToBoolean(a)); - else - return iterable.All(predicate); - } - - - #endregion - - } -} diff --git a/Python.System/Python/any.cs b/Python.System/Python/any.cs deleted file mode 100644 index f6c533d..0000000 --- a/Python.System/Python/any.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; - -namespace Python -{ - public partial class System - { - #region any - /// - /// - /// - /// - /// - /// - /// - public static bool Any(IEnumerable iterable, Func predicate = null) - => Any(iterable, predicate); - - - - - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Any)}` instead.")] -#endif - public static bool any(IEnumerable iterable, Func predicate = null) - { - if (predicate == null) - return iterable.Any(); - else - return iterable.Any(predicate); - } - - #endregion - - } -} diff --git a/Python.System/Python/bin.cs b/Python.System/Python/bin.cs deleted file mode 100644 index 787e41b..0000000 --- a/Python.System/Python/bin.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; - -namespace Python -{ - public partial class System - { - #region bin - - /// - /// 将整形的数转为二进制 - /// - /// 整数 - /// 位宽, 则不关注,如果转换结果大于位宽,则取位宽 - /// 二进制字符串 - public static string Bin(long x, int? width = null) - => Bin(x, width); - - - - - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(bin)}` instead.")] -#endif - public static string bin(long x, int? width = null) - { - if (width == null || width <= 0) - { - return "0b" + Convert.ToString(x, 2); - } - else - { - string format = Convert.ToString(x, 2); - if (format.Length < width) - { - string par = ""; - for (int c = 0; c < width - format.Length; c++) - { - par += "0"; - } - return "0b" + par + format; - } - return "0b" + format; - } - } - - #endregion - } -} diff --git a/Python.System/Python/bytearry.cs b/Python.System/Python/bytearry.cs deleted file mode 100644 index 94452fc..0000000 --- a/Python.System/Python/bytearry.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Text; - -namespace Python -{ - public partial class System - { - #region bytes - - - public static byte[] Bytes(string source, string encoding = "utf-8", string errors = "strict") - => bytes(source, encoding, errors); - /// - /// 仅支持byte sbyte int uint ushort short 数组 - /// - /// - /// - public static byte[] Bytes(IEnumerable source) => bytes(source); - public static byte[] Bytes(uint source) => bytes(source); - public static byte[] Bytes(int source) => bytes(source); - - - - - - - public static byte[] bytes(string source, string encoding = "utf-8", string errors = "strict") - => bytearray(source, encoding, errors); - /// - /// 仅支持byte sbyte int uint ushort short 数组 - /// - /// - /// - public static byte[] bytes(IEnumerable source) => bytearray(source); - public static byte[] bytes(uint source) => bytearray(source); - public static byte[] bytes(int source) => bytearray(source); - - - - #endregion - - - #region bytearry - - - public static byte[] Bytearray(string source, string encoding = "utf-8", string errors = "strict") - => bytearray(source, encoding, errors); - - public static byte[] Bytearray(uint source) => bytearray(source); - public static byte[] Bytearray(int source) => bytearray((uint)source); - - /// - /// 仅支持byte sbyte int uint ushort short 数组 - /// - /// - /// - /// - public static byte[] Bytearray(IEnumerable source) => bytearray(source); - - - - - - - public static byte[] bytearray(string source, string encoding = "utf-8", string errors = "strict") - { - return Encoding.GetEncoding(encoding, new EncoderExceptionFallback(), new DecoderExceptionFallback()).GetBytes(source); - } - - public static byte[] bytearray(uint source) => new byte[source]; - public static byte[] bytearray(int source) => bytearray((uint)source); - - /// - /// 仅支持byte sbyte int uint ushort short 数组 - /// - /// - /// - /// - public static byte[] bytearray(IEnumerable source) - { - if (source is IEnumerable bytei) - { - byte[] byteArray = bytei.ToArray(); - return byteArray; - } - else if (source is IEnumerable sbytei) - { - byte[] byteArray = sbytei.Select(i => (byte)i).ToArray(); - return byteArray; - } - else if (source is IEnumerable shorti) - { - byte[] byteArray = shorti.Select(i => (byte)i).ToArray(); - return byteArray; - } - else if (source is IEnumerable ushorti) - { - byte[] byteArray = ushorti.Select(i => (byte)i).ToArray(); - return byteArray; - } - else if (source is IEnumerable inti) - { - byte[] byteArray = inti.Select(i => (byte)i).ToArray(); - return byteArray; - } - else if (source is IEnumerable uinti) - { - byte[] byteArray = uinti.Select(i => (byte)i).ToArray(); - return byteArray; - } - else - { - throw new ArgumentException("source parameter must be an integer, a string, or an iterable object of integers or bytes"); - } - } - #endregion - } -} diff --git a/Python.System/Python/help.cs b/Python.System/Python/help.cs deleted file mode 100644 index c15b089..0000000 --- a/Python.System/Python/help.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - - -namespace Python -{ - public partial class System - { - public static void Help() - { - - } - - - - /// - /// 启动内置的帮助系统(此函数主要在交互式中使用)。 - /// 如果实参是一个字符串,则在模块、函数、类、方法、关键字或文档主题中搜索该字符串,并在控制台上打印帮助信息。 - /// 如果实参是其他任意对象,则会生成该对象的帮助页。 - /// - /// - /// - public static void Help(object request) => help(request.GetType()); - - /// - /// 启动内置的帮助系统(此函数主要在交互式中使用)。 - /// 如果实参是一个字符串,则在模块、函数、类、方法、关键字或文档主题中搜索该字符串,并在控制台上打印帮助信息。 - /// 如果实参是其他任意对象,则会生成该对象的帮助页。 - /// - /// - /// - - public static void Help(Type request) => help(request); - - - - - - - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] -#endif - public static void help() - { - print("Welcome to the Python.System, Welcome PRs => https://github.com/heartacker/Python.System"); - } - - - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] -#endif - public static void help(object request) => help(request.GetType()); - - - // //如果没有实参,解释器控制台里会启动交互式帮助系统。 - - /// - /// 启动内置的帮助系统(此函数主要在交互式中使用)。 - /// 如果实参是一个字符串,则在模块、函数、类、方法、关键字或文档主题中搜索该字符串,并在控制台上打印帮助信息。 - /// 如果实参是其他任意对象,则会生成该对象的帮助页。 - /// - /// - /// - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] -#endif - public static void help(Type request) - { - ClassHelper.ClassInfo c = ClassHelper.GetClassInfo(request); - var sb = new StringBuilder(); - - sb.AppendLine("================================================================="); - - sb.AppendLine("Name\t\t" + request.FullName); - sb.AppendLine("NameSpace\t\t\t" + request.Namespace); - sb.AppendLine("Assembly\t\t\t" + request.Assembly.FullName); - sb.AppendLine(); - sb.AppendLine("field:"); - sb.AppendLine("----------------------------------------------------------------"); - - foreach (var item in c.members) - { - if (item.Value is FieldObject) - { - sb.AppendLine($"{item.Key}:\t\t\t{((FieldObject)item.Value).fi}"); - } - } - sb.AppendLine(); - sb.AppendLine("Method:"); - sb.AppendLine("----------------------------------------------------------------"); - - foreach (var item in c.members) - { - if (item.Value is MethodObject) - { - sb.AppendLine($"{item.Key}:\t\t\t{((MethodObject)item.Value).mlist[0].ToString()}"); - } - } - sb.AppendLine(); - sb.AppendLine("================================================================="); - sb.AppendLine(); - Console.Write(sb.ToString()); - } - } -} \ No newline at end of file diff --git a/Python.System/Python/hex.cs b/Python.System/Python/hex.cs deleted file mode 100644 index 8ef4f39..0000000 --- a/Python.System/Python/hex.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Numerics; - -namespace Python -{ - public partial class System - { - #region hex - /// - /// 将整形的数转为hex - /// - /// 整数 - /// 位宽, 则不关注,如果转换结果大于位宽,则取位宽 - /// hex字符串 - public static string Hex(long x, int? width = null) - => Hex(x, width); - - /// - /// 将ulong整形的数转为hex - /// - /// 整数 - /// 位宽, 则不关注,如果转换结果大于位宽,则取位宽 - /// hex字符串 - - public static string Hex(ulong x, int? width = null) - => Hex(x, width); - - - - - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Hex)}` instead.")] -#endif - public static string hex(long x, int? width = null) - { - if (width == null || width <= 0) - { - return string.Format("0x{0:X}", x); - } - else - { - string format = "0x{0:" + "X" + width + "}"; - return string.Format(format, x); - } - } - - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Hex)}` instead.")] -#endif - public static string hex(ulong x, int? width = null) - { - if (width == null || width <= 0) - { - return string.Format("0x{0:X}", x); - } - else - { - string format = "0x{0:" + "X" + width + "}"; - return string.Format(format, x); - } - } - - #endregion - - } -} diff --git a/Python.System/Python/ord.cs b/Python.System/Python/ord.cs deleted file mode 100644 index de6917e..0000000 --- a/Python.System/Python/ord.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; - -namespace Python -{ - public partial class System - { - #region ord - - public static int Ord(char c) => ord(c); - - - - /// - /// 对表示单个 Unicode 字符的字符串,返回代表它 Unicode 码点的整数。例如 ord('a') 返回整数 97, ord('€') (欧元符号)返回 8364 。这是 chr() 的逆函数。 - /// - /// - /// - /// - public static int Ord(string c) => ord(c); - - - - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Ord)}` instead.")] -#endif - public static int ord(char c) => Convert.ToInt32(c); - - - - /// - /// 对表示单个 Unicode 字符的字符串,返回代表它 Unicode 码点的整数。例如 ord('a') 返回整数 97, ord('€') (欧元符号)返回 8364 。这是 chr() 的逆函数。 - /// - /// - /// - /// - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Ord)}` instead.")] -#endif - public static int ord(string c) - { - if (string.IsNullOrEmpty(c) || c.Length != 1) - { - throw new ArgumentException("实参必须是表示单个 Unicode 字符的字符串"); - } - return Convert.ToInt32(c[0]); - } - #endregion - - } -} diff --git a/Python.System/Python/print.cs b/Python.System/Python/print.cs deleted file mode 100644 index 5a555ac..0000000 --- a/Python.System/Python/print.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Collections; -using System.IO; -using System.Numerics; - -namespace Python -{ - public partial class System - { - #region print - - public static void Print(object @object, - string sep = " ", - string end = "\r\n", - StreamWriter file = null, - bool flush = false) => print(@object, sep, end, file, flush); - - - public static void Print(IEnumerable @object, - string sep = " ", - string end = "\r\n", - StreamWriter file = null, - bool flush = false) => print(@object, sep, end, file, flush); - - - - - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] -#endif - public static void print(object @object, - string sep = " ", - string end = "\r\n", - StreamWriter file = null, - bool flush = false) - { - var _file = file ?? Console.Out; - - _file.Write(@object); - _file.Write(end); - if (flush) _file.Flush(); - } - -#if OBSOLETE - [Obsolete("This method is deprecated, use `{nameof(Print)}` instead.")] -#endif - public static void print(IEnumerable @object, - string sep = " ", - string end = "\r\n", - StreamWriter file = null, - bool flush = false) - { - var _file = file ?? Console.Out; - if (@object is String) - { - _file.Write(@object); - _file.Write(end); - } - else - { - string str = ""; - foreach (var item in @object) - { - str += item.ToString(); - str += sep; - } - - str = str.Remove(str.Length - sep.Length, sep.Length); - - _file.Write(str); - _file.Write(end); - } - if (flush) _file.Flush(); - } - #endregion - - } -} diff --git a/Python.System/System.cs b/Python.System/System.cs deleted file mode 100644 index 9c43a55..0000000 --- a/Python.System/System.cs +++ /dev/null @@ -1,137 +0,0 @@ -using System; -using System.Collections; -using System.IO; -using System.Linq; -using System.Numerics; -using System.Collections.Generic; - - -using static System.Math; -using static System.Linq.Enumerable; -using static System.Numerics.Complex; -using static System.Numerics.BigInteger; - -#if false -using ObsoleteAttribute = System.ObsoleteAttribute; -#else -using ObsoleteAttribute = Python.Attr.ObsoleteAttribute; -#endif - -namespace Python -{ - /// - /// A: - /// abs() - /// aiter() // x - /// all() - /// any() - /// anext() - /// ascii() - /// - /// B: - /// bin() - /// bool() - /// breakpoint() - /// bytearray() - /// bytes() - /// - /// C: - /// callable() - /// chr() - /// classmethod() - /// compile() - /// complex() - /// - /// D: - /// delattr() - /// dict() - /// dir() - /// divmod() - /// - /// E: - /// enumerate() - /// eval() - /// exec() - /// - /// F: - /// filter() - /// float() - /// format() - /// frozenset() - /// - /// G: - /// getattr() - /// globals() - /// - /// H: - /// hasattr() - /// hash() - /// help() - /// hex() - /// - /// I: - /// id() - /// input() - /// int() - /// isinstance() - /// issubclass() - /// iter() - /// - /// L: - /// len() - /// list() - /// locals() - /// - /// M: - /// map() - /// max() - /// memoryview() - /// min() - /// - /// N: - /// next() - /// - /// O: - /// object() - /// oct() - /// open() - /// ord() - /// - /// P: - /// pow() - /// print() - /// property() - /// - /// R: - /// range() - /// repr() - /// reversed() - /// round() - /// - /// S: - /// set() - /// setattr() - /// slice() - /// sorted() - /// staticmethod() - /// str() - /// sum() - /// super() - /// - /// T: - /// tuple() - /// type() - /// - /// V: - /// vars() - /// - /// Z: - /// zip() - /// - /// _ - /// __import__() - /// - public static partial class System - { - } -} \ No newline at end of file diff --git a/Python.SystemDemo/Properties/launchSettings.json b/Python.SystemDemo/Properties/launchSettings.json deleted file mode 100644 index 1f5332b..0000000 --- a/Python.SystemDemo/Properties/launchSettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "profiles": { - "Python.SystemDemo": { - "commandName": "Project", - "commandLineArgs": "Hello Python.System" - } - } -} \ No newline at end of file diff --git a/README.md b/README.md index 813bca1..66e8239 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# 1. Python.System +# 1. CScripting -[![GitHub stars](https://img.shields.io/github/stars/heartacker/Python.System?style=for-the-badge)](https://github.com/heartacker/Python.System) -[![Nuget](https://img.shields.io/nuget/v/Python.System?style=for-the-badge)](https://www.nuget.org/packages/Python.System) -![Nuget](https://img.shields.io/nuget/dt/Python.System?style=for-the-badge) -[![GitHub release](https://img.shields.io/github/v/release/heartacker/Python.System?style=for-the-badge)](https://github.com/heartacker/Python.System/releases) +[![GitHub stars](https://img.shields.io/github/stars/heartacker/CScripting?style=for-the-badge)](https://github.com/heartacker/CScripting) +[![Nuget](https://img.shields.io/nuget/v/CScripting?style=for-the-badge)](https://www.nuget.org/packages/CScripting) +![Nuget](https://img.shields.io/nuget/dt/CScripting?style=for-the-badge) +[![GitHub release](https://img.shields.io/github/v/release/heartacker/CScripting?style=for-the-badge)](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) @@ -14,7 +14,7 @@ -- [1. Python.System](#1-pythonsystem) +- [1. CScripting](#1-cscripting) - [1.1. Instruction](#11-instruction) - [1.2. Recent Changelog](#12-recent-changelog) - [1.3. Demo](#13-demo) @@ -51,7 +51,7 @@ 3. add `dir` function 4. fix trim `print()` last sep -more information, see [CHANGELOG.md](https://github.com/heartacker/Python.System/blob/master/CHANGELOG.md) +more information, see [CHANGELOG.md](https://github.com/heartacker/CScripting/blob/master/CHANGELOG.md) ## 1.3. Demo @@ -62,11 +62,11 @@ more information, see [CHANGELOG.md](https://github.com/heartacker/Python.System -🔗 [**C#**](./Python.System.Demo.csx) +🔗 [**C#**](./CScripting.Demo.csx) ```csharp -#r "nuget: Python.System, *" -using static Python.System; +#r "nuget: CScripting, *" +using static CScripting; var addr = 0x12345678; var addrr = hex(addr); @@ -91,10 +91,10 @@ print(c, sep:"\t"); -🔗 [**Python**](./Python.System.Compare.py) +🔗 [**Built-in**](./CScripting.Compare.py) ```python -#r "nuget: Python.System, *" +#r "nuget: CScripting, *" addr = 0x12345678 @@ -165,8 +165,8 @@ print(c, sep="\t") ```shell ~$ dotnet-script -> #r "nuget: Python.System, *" -> using static Python.System; +> #r "nuget: CScripting, *" +> using static CScripting; > hex(1024) "0x400" > print("Hello Scripy") @@ -189,23 +189,23 @@ Hello Scripy ## 1.7. `Python` Built-in function list - A - - [x] [`abs()`](./Python.System/Python/abs.cs) + - [x] [`abs()`](./CScripting/Built-in/abs.cs) - [ ] `aiter()` - - [x] [`all()`](./Python.System/Python/all.cs) - - [x] [`any()`](./Python.System/Python/any.cs) + - [x] [`all()`](./CScripting/Built-in/all.cs) + - [x] [`any()`](./CScripting/Built-in/any.cs) - [ ] `anext()` - [ ] `ascii()` - B - - [x] [`bin()`](./Python.System/Python/bin.cs) + - [x] [`bin()`](./CScripting/Built-in/bin.cs) - [ ] `bool()` - [ ] `breakpoint()` - - [x] [`bytearray()`](./Python.System/Python/bytearry.cs) - - [x] [`bytes()`](./Python.System/Python/bytearry.cs) + - [x] [`bytearray()`](./CScripting/Built-in/bytearry.cs) + - [x] [`bytes()`](./CScripting/Built-in/bytearry.cs) - C - [ ] `callable()` - - [x] [`chr()`](./Python.System/Python/chr.cs) + - [x] [`chr()`](./CScripting/Built-in/chr.cs) - [ ] `classmethod()` - [ ] `compile()` ** - [ ] `complex()` ** @@ -234,8 +234,8 @@ Hello Scripy - H - [ ] `hasattr()` - [ ] `hash()` - - [x] [`help()`](./Python.System/Python/help.cs) - - [x] [`hex()`](./Python.System/Python/hex.cs) + - [x] [`help()`](./CScripting/Built-in/help.cs) + - [x] [`hex()`](./CScripting/Built-in/hex.cs) - I - [ ] `id()` @@ -261,13 +261,13 @@ Hello Scripy - O - [ ] `object()` - - [x] [`oct()`](./Python.System/Python/oct.cs) + - [x] [`oct()`](./CScripting/Built-in/oct.cs) - [ ] `open()` - - [x] [`ord()`](./Python.System/Python/ord.cs) + - [x] [`ord()`](./CScripting/Built-in/ord.cs) - P - [ ] `pow()` - - [x] [`print()`](./Python.System/Python/print.cs) + - [x] [`print()`](./CScripting/Built-in/print.cs) - [ ] `property()` - R From 61d5f5f5f809b8fef8047c45dbe35fd8a55f2580 Mon Sep 17 00:00:00 2001 From: heartacker Date: Tue, 16 May 2023 16:23:19 +0800 Subject: [PATCH 56/74] Python --- CSharp.Scripting.csx | 1 - 1 file changed, 1 deletion(-) diff --git a/CSharp.Scripting.csx b/CSharp.Scripting.csx index 798fc0e..3922759 100644 --- a/CSharp.Scripting.csx +++ b/CSharp.Scripting.csx @@ -1,7 +1,6 @@ #r "nuget: CScripting, *" #r "nuget: Microsoft.CodeAnalysis.CSharp.Scripting, *" -using Python; using static CScripting; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Scripting; From 5639daaf89c615fe77ecae9a51eb1bb273187b93 Mon Sep 17 00:00:00 2001 From: heartacker Date: Wed, 17 May 2023 16:35:52 +0800 Subject: [PATCH 57/74] =?UTF-8?q?array=20list=20dictory=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BB=A3=E7=A0=81=E5=BD=A2=E5=BC=8F=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CScripting/Built-in/print.cs | 73 +++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/CScripting/Built-in/print.cs b/CScripting/Built-in/print.cs index fc2130d..5ee5d9b 100644 --- a/CScripting/Built-in/print.cs +++ b/CScripting/Built-in/print.cs @@ -1,6 +1,8 @@ using System; -using System.Collections; using System.IO; +using System.Linq; +using System.Collections; +using System.Collections.Generic; using System.Numerics; #if WITH_NAME_SPACE @@ -60,6 +62,75 @@ public static void print(IEnumerable @object, _file.Write(@object); _file.Write(end); } + else if ((@object is Array && sep == " ")) + { + dynamic objs = @object; + var isString = false; + if ((objs as Array).Length >= 1) + isString = ((dynamic)objs)[0] is string; + string str = "{"; + foreach (var item in objs) + { + if (isString) str += "\""; + str += item.ToString(); + if (isString) str += "\""; + str += ", "; + } + str = str.Remove(str.Length - ", ".Length, ", ".Length); + str += "}"; + _file.Write(str); + _file.Write(end); + } + else if ((@object is IList && sep == " ")) + { + dynamic objs = @object; + var isString = false; + if ((objs as IList).Count >= 1) + isString = ((dynamic)objs)[0] is string; + string str = "{"; + foreach (var item in objs) + { + if (isString) str += "\""; + str += item.ToString(); + if (isString) str += "\""; + str += ", "; + } + str = str.Remove(str.Length - ", ".Length, ", ".Length); + str += "}"; + _file.Write(str); + _file.Write(end); + } + else if ((@object is IDictionary)) + { + IDictionary objs = @object as IDictionary; + var isKeyString = false; + var isValueString = false; + foreach (var item in (dynamic)objs) + { + isKeyString = item.Key is string; + isValueString = item.Value is string; + break; + } + string str = "{"; + foreach (var item in (dynamic)objs) + { + str += "{"; + if (isKeyString) str += "\""; + str += item.Key.ToString(); + if (isKeyString) str += "\""; + str += ", "; + + if (isValueString) str += "\""; + str += item.Value.ToString(); + if (isValueString) str += "\""; + str += "}"; + str += ", "; + } + str = str.Remove(str.Length - ", ".Length, ", ".Length); + str += "}"; + _file.Write(str); + _file.Write(end); + } else { string str = ""; From 67f156259257037019eee9d2879ebd8c75d4fb54 Mon Sep 17 00:00:00 2001 From: heartacker Date: Wed, 17 May 2023 16:36:07 +0800 Subject: [PATCH 58/74] demo --- CScriptingDemo/CScriptingDemo.cs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/CScriptingDemo/CScriptingDemo.cs b/CScriptingDemo/CScriptingDemo.cs index 205d52c..dc5cda1 100644 --- a/CScriptingDemo/CScriptingDemo.cs +++ b/CScriptingDemo/CScriptingDemo.cs @@ -10,14 +10,36 @@ public static void Main(string[] args) print(eargs); print("hello world"); - uint[] a = { 1, 2, 3, 4, 5, 6, 7 }; + print("hello world", "\t");// \t no use + int[] a = { 1, 2, 3, 4, 5, 6, 7 }; print(a); - print(a, sep: "\t"); - - + print(a, sep: "\t"); // \t ok + + List b = new() + { + 1, + 2 + }; + print(b); + print(b, sep: "\t"); + Dictionary d = new() + { + { "a", 1 }, + { "b", 2 } + }; + print(d); + print(d, sep: "\t"); + Dictionary d2 = new() + { + { 1, "a" }, + { 2, "b" } + }; + print(d2); + print(d2, sep: "\t"); help(); + help(d2); help(a); help(typeof(Math)); From 9df79e81656a369db8cd75b030aeccde6b6b1827 Mon Sep 17 00:00:00 2001 From: heartacker Date: Wed, 17 May 2023 16:36:26 +0800 Subject: [PATCH 59/74] no problem Matcher --- .vscode/tasks.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 26ed5a0..eca0c85 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -33,7 +33,7 @@ "presentation": { "reveal": "silent" }, - "problemMatcher": "$msCompile" + // "problemMatcher": "$msCompile" }, ] } \ No newline at end of file From 40e410b54651ca5b5379dbea0b87ba4e10149565 Mon Sep 17 00:00:00 2001 From: heartacker Date: Wed, 17 May 2023 16:42:10 +0800 Subject: [PATCH 60/74] update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 66e8239..db91eee 100644 --- a/README.md +++ b/README.md @@ -135,8 +135,8 @@ print(c, sep="\t") 0x12345678 305419896 0b10010001101000101011001111000 -0 1 2 3 4 5 6 7 -0 1 2 3 4 5 6 7 +{ 0, 1, 2, 3, 4, 5, 6, 7} +0 1 2 3 4 5 6 7 ``` From 25da60fde9ba221b59d052fce39ab7cb7ed78fa4 Mon Sep 17 00:00:00 2001 From: heartacker Date: Thu, 18 May 2023 21:00:41 +0800 Subject: [PATCH 61/74] fixLens --- CScripting/Built-in/help.cs | 12 ++++++------ CScripting/StringHelper.cs | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 CScripting/StringHelper.cs diff --git a/CScripting/Built-in/help.cs b/CScripting/Built-in/help.cs index 8f6af32..30b33ea 100644 --- a/CScripting/Built-in/help.cs +++ b/CScripting/Built-in/help.cs @@ -80,18 +80,18 @@ public static void help(Type request) sb.AppendLine("================================================================="); - sb.AppendLine("Name\t\t" + request.FullName); - sb.AppendLine("NameSpace\t\t\t" + request.Namespace); - sb.AppendLine("Assembly\t\t\t" + request.Assembly.FullName); + sb.AppendLine("Name".FixLens() + "\t" + request.FullName); + sb.AppendLine("NameSpace".FixLens() + "\t" + request.Namespace); + sb.AppendLine("Assembly".FixLens() + "\t" + request.Assembly.FullName); sb.AppendLine(); - sb.AppendLine("field:"); + sb.AppendLine("field"); sb.AppendLine("----------------------------------------------------------------"); foreach (var item in c.members) { if (item.Value is FieldObject) { - sb.AppendLine($"{item.Key}:\t\t\t{((FieldObject)item.Value).fi}"); + sb.AppendLine($"{item.Key.ToString().FixLens()}\t{((FieldObject)item.Value).fi}"); } } sb.AppendLine(); @@ -102,7 +102,7 @@ public static void help(Type request) { if (item.Value is MethodObject) { - sb.AppendLine($"{item.Key}:\t\t\t{((MethodObject)item.Value).mlist[0].ToString()}"); + sb.AppendLine($"{item.Key.ToString().FixLens()}\t{((MethodObject)item.Value).mlist[0]}"); } } sb.AppendLine(); diff --git a/CScripting/StringHelper.cs b/CScripting/StringHelper.cs new file mode 100644 index 0000000..27020a3 --- /dev/null +++ b/CScripting/StringHelper.cs @@ -0,0 +1,20 @@ +public static class StringExternsion +{ + public static string FixLens(this string str, int length = 16, string sep = " ") + { + var diff = length - str.Length; + if (diff > 0) + { + for (int i = 0; i < diff; i++) + { + str += sep; + } + } + return str; + } +} + +public static class StringHelper +{ + +} From 8eefd969475772853e58e037a48201e837afec0b Mon Sep 17 00:00:00 2001 From: heartacker Date: Thu, 18 May 2023 21:01:22 +0800 Subject: [PATCH 62/74] 0.0.2 --- CScripting.Demo.dib | 4 ++++ CScripting/CScripting.csproj | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CScripting.Demo.dib b/CScripting.Demo.dib index f810359..99bb0bb 100644 --- a/CScripting.Demo.dib +++ b/CScripting.Demo.dib @@ -70,3 +70,7 @@ print(_12); help(typeof(System.Math)); help(typeof(System.IO.File)); + +#!csharp + +print(bytes(5)) diff --git a/CScripting/CScripting.csproj b/CScripting/CScripting.csproj index 71bf177..cb0ad89 100644 --- a/CScripting/CScripting.csproj +++ b/CScripting/CScripting.csproj @@ -20,7 +20,7 @@ git static;python;function;script;CScripting;csharpscript;matlab;cli see https://github.com/heartacker/CScripting/blob/master/CHANGELOG.md - 0.0.1-preview2023-5-16 + 0.0.2 CScripting $(MSBuildProjectName) README.md @@ -34,6 +34,8 @@ + + From f3a325c29267993c50de35e73315e8e7b920124f Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 20 May 2023 18:11:34 +0800 Subject: [PATCH 63/74] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db91eee..704e81a 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ print(c, sep:"\t"); -🔗 [**Built-in**](./CScripting.Compare.py) +🔗 [**Python**](./CScripting.Compare.py) ```python #r "nuget: CScripting, *" From 8542c3dbe7e16d7497eedf64362b98162f634dbb Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 11 Nov 2023 14:57:54 +0800 Subject: [PATCH 64/74] repo-visualization --- .github/workflows/diagram.yml | 16 ++++++++++++++++ README.md | 2 ++ 2 files changed, 18 insertions(+) create mode 100644 .github/workflows/diagram.yml diff --git a/.github/workflows/diagram.yml b/.github/workflows/diagram.yml new file mode 100644 index 0000000..c005e8b --- /dev/null +++ b/.github/workflows/diagram.yml @@ -0,0 +1,16 @@ +name: Create diagram +on: + workflow_dispatch: {} + push: + branches: + - master +jobs: + get_data: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@master + - name: Update diagram + uses: githubocto/repo-visualizer@master + with: + excluded_paths: "ignore,.github" diff --git a/README.md b/README.md index 704e81a..8ec65d6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # 1. CScripting +![Visualization of the codebase](./diagram.svg) + [![GitHub stars](https://img.shields.io/github/stars/heartacker/CScripting?style=for-the-badge)](https://github.com/heartacker/CScripting) [![Nuget](https://img.shields.io/nuget/v/CScripting?style=for-the-badge)](https://www.nuget.org/packages/CScripting) ![Nuget](https://img.shields.io/nuget/dt/CScripting?style=for-the-badge) From d29c4178621c7e18d39f1f962dd302dc65926135 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 11 Nov 2023 14:59:21 +0800 Subject: [PATCH 65/74] main --- .github/workflows/diagram.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/diagram.yml b/.github/workflows/diagram.yml index c005e8b..d13edd9 100644 --- a/.github/workflows/diagram.yml +++ b/.github/workflows/diagram.yml @@ -11,6 +11,6 @@ jobs: - name: Checkout code uses: actions/checkout@master - name: Update diagram - uses: githubocto/repo-visualizer@master + uses: githubocto/repo-visualizer@main with: excluded_paths: "ignore,.github" From fc22094e2a773231692cd25c92ecdb4a867940c7 Mon Sep 17 00:00:00 2001 From: repo-visualizer Date: Sat, 11 Nov 2023 07:03:54 +0000 Subject: [PATCH 66/74] Repo visualizer: update diagram --- diagram.svg | 1 + 1 file changed, 1 insertion(+) create mode 100644 diagram.svg diff --git a/diagram.svg b/diagram.svg new file mode 100644 index 0000000..ca3103e --- /dev/null +++ b/diagram.svg @@ -0,0 +1 @@ +CScriptingTestsCScriptingTestsCScriptingDemoCScriptingDemoCScriptingCScripting.vscode.vscodeEngineEngineBuilt-inBuilt-inMatlabMatlab.gitignore.gitignore.gitignoreREADME.mdREADME.mdREADME.md.gitattributes.gitattributes.gitattributesCScripting.slnCScripting.slnCScripting.slnCSharp.Scri...CSharp.Scri...CSharp.Scri...CScripti...CScripti...CScripti...Built-in/CScrip...Built-in/CScrip...Built-in/CScrip...Properties/laun...Properties/laun...Properties/laun...CScriptin...CScriptin...CScriptin...CScripting.csCScripting.csCScripting.csCScripting....CScripting....CScripting....launch.jsonlaunch.jsonlaunch.jsontasks.jsontasks.jsontasks.jsonClassHelper.csClassHelper.csClassHelper.csOpsHelper.csOpsHelper.csOpsHelper.csExtensionT...ExtensionT...ExtensionT...Reflectio...Reflectio...Reflectio...ClassBase.csClassBase.csClassBase.csprint.csprint.csprint.csbytearry.csbytearry.csbytearry.cshelp.cshelp.cshelp.csabs.csabs.csabs.cschr.cschr.cschr.cshex.cshex.cshex.csord.csord.csord.csoct.csoct.csoct.csbin.csbin.csbin.csall.csall.csall.csany.csany.csany.cs.cs.csproj.csx.gitignore.json.md.pyeach dot sized by file size \ No newline at end of file From ffb146fef8fda1e07e5ea60ea911a5e3853b3ed8 Mon Sep 17 00:00:00 2001 From: heartacker Date: Tue, 28 May 2024 11:46:31 +0800 Subject: [PATCH 67/74] nuget update --- .vscode/launch.json | 4 ++-- CScriptingDemo/CScriptingDemo.csproj | 2 +- CScriptingTests/CScriptingTests.csproj | 13 ++++++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index b3fc1d1..8257239 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -32,12 +32,12 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "buildDemo", - "program": "${workspaceFolder}/CScriptingDemo/bin/Debug/net7.0-windows/CScriptingDemo.exe", + "program": "${workspaceFolder}/CScriptingDemo/bin/Debug/net8.0-windows/CScriptingDemo.dll", "requireExactSource": false, "args": [], "cwd": "${workspaceFolder}", "stopAtEntry": false, - "console": "internalConsole" + "console": "integratedTerminal" }, ] } \ No newline at end of file diff --git a/CScriptingDemo/CScriptingDemo.csproj b/CScriptingDemo/CScriptingDemo.csproj index e7f9154..ae671b5 100644 --- a/CScriptingDemo/CScriptingDemo.csproj +++ b/CScriptingDemo/CScriptingDemo.csproj @@ -2,7 +2,7 @@ Exe - net7.0-windows + net8.0-windows enable enable diff --git a/CScriptingTests/CScriptingTests.csproj b/CScriptingTests/CScriptingTests.csproj index 52d0b33..7a4f945 100644 --- a/CScriptingTests/CScriptingTests.csproj +++ b/CScriptingTests/CScriptingTests.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable enable @@ -10,10 +10,13 @@ - - - - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + From ce930a538581e5d620cd3fc9990aaf25b82d41cd Mon Sep 17 00:00:00 2001 From: repo-visualizer Date: Tue, 28 May 2024 03:46:56 +0000 Subject: [PATCH 68/74] Repo visualizer: update diagram --- diagram.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diagram.svg b/diagram.svg index ca3103e..caf4707 100644 --- a/diagram.svg +++ b/diagram.svg @@ -1 +1 @@ -CScriptingTestsCScriptingTestsCScriptingDemoCScriptingDemoCScriptingCScripting.vscode.vscodeEngineEngineBuilt-inBuilt-inMatlabMatlab.gitignore.gitignore.gitignoreREADME.mdREADME.mdREADME.md.gitattributes.gitattributes.gitattributesCScripting.slnCScripting.slnCScripting.slnCSharp.Scri...CSharp.Scri...CSharp.Scri...CScripti...CScripti...CScripti...Built-in/CScrip...Built-in/CScrip...Built-in/CScrip...Properties/laun...Properties/laun...Properties/laun...CScriptin...CScriptin...CScriptin...CScripting.csCScripting.csCScripting.csCScripting....CScripting....CScripting....launch.jsonlaunch.jsonlaunch.jsontasks.jsontasks.jsontasks.jsonClassHelper.csClassHelper.csClassHelper.csOpsHelper.csOpsHelper.csOpsHelper.csExtensionT...ExtensionT...ExtensionT...Reflectio...Reflectio...Reflectio...ClassBase.csClassBase.csClassBase.csprint.csprint.csprint.csbytearry.csbytearry.csbytearry.cshelp.cshelp.cshelp.csabs.csabs.csabs.cschr.cschr.cschr.cshex.cshex.cshex.csord.csord.csord.csoct.csoct.csoct.csbin.csbin.csbin.csall.csall.csall.csany.csany.csany.cs.cs.csproj.csx.gitignore.json.md.pyeach dot sized by file size \ No newline at end of file +CScriptingTestsCScriptingTestsCScriptingDemoCScriptingDemoCScriptingCScripting.vscode.vscodeEngineEngineBuilt-inBuilt-inMatlabMatlab.gitignore.gitignore.gitignoreREADME.mdREADME.mdREADME.md.gitattributes.gitattributes.gitattributesCScripting.slnCScripting.slnCScripting.slnCSharp.Scri...CSharp.Scri...CSharp.Scri...CScripti...CScripti...CScripti...Built-in/CScrip...Built-in/CScrip...Built-in/CScrip...CScripti...CScripti...CScripti...Properties/laun...Properties/laun...Properties/laun...CScriptin...CScriptin...CScriptin...CScripting.csCScripting.csCScripting.csCScripting....CScripting....CScripting....launch.jsonlaunch.jsonlaunch.jsontasks.jsontasks.jsontasks.jsonClassHelper.csClassHelper.csClassHelper.csOpsHelper.csOpsHelper.csOpsHelper.csExtensionT...ExtensionT...ExtensionT...Reflectio...Reflectio...Reflectio...ClassBase.csClassBase.csClassBase.csprint.csprint.csprint.csbytearry.csbytearry.csbytearry.cshelp.cshelp.cshelp.csabs.csabs.csabs.cschr.cschr.cschr.cshex.cshex.cshex.csord.csord.csord.csoct.csoct.csoct.csbin.csbin.csbin.csall.csall.csall.csany.csany.csany.cs.cs.csproj.csx.gitignore.json.md.py.svgeach dot sized by file size \ No newline at end of file From 2b0cf131e7cb85f9525eb735f0f733c4729008f3 Mon Sep 17 00:00:00 2001 From: heartacker Date: Tue, 28 May 2024 13:01:54 +0800 Subject: [PATCH 69/74] Scripy --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8ec65d6..9e4cbd1 100644 --- a/README.md +++ b/README.md @@ -171,8 +171,8 @@ print(c, sep="\t") > using static CScripting; > hex(1024) "0x400" -> print("Hello Scripy") -Hello Scripy +> print("Hello CScripting") +Hello CScripting ``` From a3501281774c2b7379ff41b2281b1f3181484357 Mon Sep 17 00:00:00 2001 From: repo-visualizer Date: Tue, 28 May 2024 05:02:21 +0000 Subject: [PATCH 70/74] Repo visualizer: update diagram --- diagram.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diagram.svg b/diagram.svg index caf4707..51646da 100644 --- a/diagram.svg +++ b/diagram.svg @@ -1 +1 @@ -CScriptingTestsCScriptingTestsCScriptingDemoCScriptingDemoCScriptingCScripting.vscode.vscodeEngineEngineBuilt-inBuilt-inMatlabMatlab.gitignore.gitignore.gitignoreREADME.mdREADME.mdREADME.md.gitattributes.gitattributes.gitattributesCScripting.slnCScripting.slnCScripting.slnCSharp.Scri...CSharp.Scri...CSharp.Scri...CScripti...CScripti...CScripti...Built-in/CScrip...Built-in/CScrip...Built-in/CScrip...CScripti...CScripti...CScripti...Properties/laun...Properties/laun...Properties/laun...CScriptin...CScriptin...CScriptin...CScripting.csCScripting.csCScripting.csCScripting....CScripting....CScripting....launch.jsonlaunch.jsonlaunch.jsontasks.jsontasks.jsontasks.jsonClassHelper.csClassHelper.csClassHelper.csOpsHelper.csOpsHelper.csOpsHelper.csExtensionT...ExtensionT...ExtensionT...Reflectio...Reflectio...Reflectio...ClassBase.csClassBase.csClassBase.csprint.csprint.csprint.csbytearry.csbytearry.csbytearry.cshelp.cshelp.cshelp.csabs.csabs.csabs.cschr.cschr.cschr.cshex.cshex.cshex.csord.csord.csord.csoct.csoct.csoct.csbin.csbin.csbin.csall.csall.csall.csany.csany.csany.cs.cs.csproj.csx.gitignore.json.md.py.svgeach dot sized by file size \ No newline at end of file +CScriptingTestsCScriptingTestsCScriptingDemoCScriptingDemoCScriptingCScripting.vscode.vscodeEngineEngineBuilt-inBuilt-inMatlabMatlab.gitignore.gitignore.gitignoreREADME.mdREADME.mdREADME.md.gitattributes.gitattributes.gitattributesCScripting.slnCScripting.slnCScripting.slnCSharp.Scri...CSharp.Scri...CSharp.Scri...CScripti...CScripti...CScripti...Built-in/CScrip...Built-in/CScrip...Built-in/CScrip...CScripti...CScripti...CScripti...Properties/laun...Properties/laun...Properties/laun...CScriptin...CScriptin...CScriptin...CScripting.csCScripting.csCScripting.csCScripting....CScripting....CScripting....launch.jsonlaunch.jsonlaunch.jsontasks.jsontasks.jsontasks.jsonClassHelper.csClassHelper.csClassHelper.csOpsHelper.csOpsHelper.csOpsHelper.csExtensionT...ExtensionT...ExtensionT...Reflectio...Reflectio...Reflectio...ClassBase.csClassBase.csClassBase.csprint.csprint.csprint.csbytearry.csbytearry.csbytearry.cshelp.cshelp.cshelp.csabs.csabs.csabs.cschr.cschr.cschr.cshex.cshex.cshex.csord.csord.csord.csoct.csoct.csoct.csbin.csbin.csbin.csall.csall.csall.csany.csany.csany.cs.cs.csproj.csx.gitignore.json.md.py.svgeach dot sized by file size \ No newline at end of file From e322c66673257ff18ec2cd0ff905c4c5913c6c4e Mon Sep 17 00:00:00 2001 From: heartacker Date: Tue, 28 May 2024 14:11:08 +0800 Subject: [PATCH 71/74] ignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9491a2f..9d22c05 100644 --- a/.gitignore +++ b/.gitignore @@ -360,4 +360,5 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd +_c_demo/** From 32464003d2da77d2de1c11dcaf225128a18c60b5 Mon Sep 17 00:00:00 2001 From: repo-visualizer Date: Tue, 28 May 2024 06:23:52 +0000 Subject: [PATCH 72/74] Repo visualizer: update diagram --- diagram.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diagram.svg b/diagram.svg index 51646da..1265d88 100644 --- a/diagram.svg +++ b/diagram.svg @@ -1 +1 @@ -CScriptingTestsCScriptingTestsCScriptingDemoCScriptingDemoCScriptingCScripting.vscode.vscodeEngineEngineBuilt-inBuilt-inMatlabMatlab.gitignore.gitignore.gitignoreREADME.mdREADME.mdREADME.md.gitattributes.gitattributes.gitattributesCScripting.slnCScripting.slnCScripting.slnCSharp.Scri...CSharp.Scri...CSharp.Scri...CScripti...CScripti...CScripti...Built-in/CScrip...Built-in/CScrip...Built-in/CScrip...CScripti...CScripti...CScripti...Properties/laun...Properties/laun...Properties/laun...CScriptin...CScriptin...CScriptin...CScripting.csCScripting.csCScripting.csCScripting....CScripting....CScripting....launch.jsonlaunch.jsonlaunch.jsontasks.jsontasks.jsontasks.jsonClassHelper.csClassHelper.csClassHelper.csOpsHelper.csOpsHelper.csOpsHelper.csExtensionT...ExtensionT...ExtensionT...Reflectio...Reflectio...Reflectio...ClassBase.csClassBase.csClassBase.csprint.csprint.csprint.csbytearry.csbytearry.csbytearry.cshelp.cshelp.cshelp.csabs.csabs.csabs.cschr.cschr.cschr.cshex.cshex.cshex.csord.csord.csord.csoct.csoct.csoct.csbin.csbin.csbin.csall.csall.csall.csany.csany.csany.cs.cs.csproj.csx.gitignore.json.md.py.svgeach dot sized by file size \ No newline at end of file +CScriptingTestsCScriptingTestsCScriptingDemoCScriptingDemoCScriptingCScripting.vscode.vscodeEngineEngineBuilt-inBuilt-inMatlabMatlab.gitignore.gitignore.gitignoreREADME.mdREADME.mdREADME.md.gitattributes.gitattributes.gitattributesCScripting.slnCScripting.slnCScripting.slnCSharp.Scri...CSharp.Scri...CSharp.Scri...CScripti...CScripti...CScripti...Built-in/CScrip...Built-in/CScrip...Built-in/CScrip...CScripti...CScripti...CScripti...Properties/laun...Properties/laun...Properties/laun...CScriptin...CScriptin...CScriptin...CScripting.csCScripting.csCScripting.csCScripting....CScripting....CScripting....launch.jsonlaunch.jsonlaunch.jsontasks.jsontasks.jsontasks.jsonClassHelper.csClassHelper.csClassHelper.csOpsHelper.csOpsHelper.csOpsHelper.csExtensionT...ExtensionT...ExtensionT...Reflectio...Reflectio...Reflectio...ClassBase.csClassBase.csClassBase.csprint.csprint.csprint.csbytearry.csbytearry.csbytearry.cshelp.cshelp.cshelp.csabs.csabs.csabs.cschr.cschr.cschr.cshex.cshex.cshex.csord.csord.csord.csoct.csoct.csoct.csbin.csbin.csbin.csall.csall.csall.csany.csany.csany.cs.cs.csproj.csx.gitignore.json.md.py.svgeach dot sized by file size \ No newline at end of file From f1d60ad44048410df9a6235e9ebe36eaea71891c Mon Sep 17 00:00:00 2001 From: heartacker Date: Tue, 28 May 2024 14:29:58 +0800 Subject: [PATCH 73/74] 8 --- omnisharp.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omnisharp.json b/omnisharp.json index ff68708..945a3c2 100644 --- a/omnisharp.json +++ b/omnisharp.json @@ -1,6 +1,6 @@ { "script": { "enableScriptNuGetReferences": true, - "defaultTargetFramework": "net7.0" + "defaultTargetFramework": "net8.0" } } \ No newline at end of file From 85b08c0335a1df4fe737f30b336315813f952081 Mon Sep 17 00:00:00 2001 From: repo-visualizer Date: Tue, 28 May 2024 06:30:24 +0000 Subject: [PATCH 74/74] Repo visualizer: update diagram --- diagram.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diagram.svg b/diagram.svg index 1265d88..49d1785 100644 --- a/diagram.svg +++ b/diagram.svg @@ -1 +1 @@ -CScriptingTestsCScriptingTestsCScriptingDemoCScriptingDemoCScriptingCScripting.vscode.vscodeEngineEngineBuilt-inBuilt-inMatlabMatlab.gitignore.gitignore.gitignoreREADME.mdREADME.mdREADME.md.gitattributes.gitattributes.gitattributesCScripting.slnCScripting.slnCScripting.slnCSharp.Scri...CSharp.Scri...CSharp.Scri...CScripti...CScripti...CScripti...Built-in/CScrip...Built-in/CScrip...Built-in/CScrip...CScripti...CScripti...CScripti...Properties/laun...Properties/laun...Properties/laun...CScriptin...CScriptin...CScriptin...CScripting.csCScripting.csCScripting.csCScripting....CScripting....CScripting....launch.jsonlaunch.jsonlaunch.jsontasks.jsontasks.jsontasks.jsonClassHelper.csClassHelper.csClassHelper.csOpsHelper.csOpsHelper.csOpsHelper.csExtensionT...ExtensionT...ExtensionT...Reflectio...Reflectio...Reflectio...ClassBase.csClassBase.csClassBase.csprint.csprint.csprint.csbytearry.csbytearry.csbytearry.cshelp.cshelp.cshelp.csabs.csabs.csabs.cschr.cschr.cschr.cshex.cshex.cshex.csord.csord.csord.csoct.csoct.csoct.csbin.csbin.csbin.csall.csall.csall.csany.csany.csany.cs.cs.csproj.csx.gitignore.json.md.py.svgeach dot sized by file size \ No newline at end of file +CScriptingTestsCScriptingTestsCScriptingDemoCScriptingDemoCScriptingCScripting.vscode.vscodeEngineEngineBuilt-inBuilt-inMatlabMatlab.gitignore.gitignore.gitignoreREADME.mdREADME.mdREADME.md.gitattributes.gitattributes.gitattributesCScripting.slnCScripting.slnCScripting.slnCSharp.Scri...CSharp.Scri...CSharp.Scri...CScripti...CScripti...CScripti...Built-in/CScrip...Built-in/CScrip...Built-in/CScrip...CScripti...CScripti...CScripti...Properties/laun...Properties/laun...Properties/laun...CScriptin...CScriptin...CScriptin...CScripting.csCScripting.csCScripting.csCScripting....CScripting....CScripting....launch.jsonlaunch.jsonlaunch.jsontasks.jsontasks.jsontasks.jsonClassHelper.csClassHelper.csClassHelper.csOpsHelper.csOpsHelper.csOpsHelper.csExtensionT...ExtensionT...ExtensionT...Reflectio...Reflectio...Reflectio...ClassBase.csClassBase.csClassBase.csprint.csprint.csprint.csbytearry.csbytearry.csbytearry.cshelp.cshelp.cshelp.csabs.csabs.csabs.cschr.cschr.cschr.cshex.cshex.cshex.csord.csord.csord.csoct.csoct.csoct.csbin.csbin.csbin.csall.csall.csall.csany.csany.csany.cs.cs.csproj.csx.gitignore.json.md.py.svgeach dot sized by file size \ No newline at end of file