File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ var a = 1 + 2 ;
2+ print ( a ) ;
3+ return a ;
Original file line number Diff line number Diff line change 1+ #r "nuget: Python.System, *"
2+ #r "nuget : Microsoft . CodeAnalysis . CSharp . Scripting , * "
3+ using Python;
4+ using static Python . System ;
5+ using Microsoft . CodeAnalysis . CSharp . Scripting ;
6+ using Microsoft . CodeAnalysis . Scripting ;
7+ using System . IO ;
8+
9+ Console . WriteLine ( @"测试输入输出函数:Directory.GetCurrentDirectory()" ) ;
10+ var res = await CSharpScript . EvaluateAsync ( "Directory.GetCurrentDirectory()" ,
11+ ScriptOptions . Default . WithImports ( "System.IO" ) ) ;
12+ Console . WriteLine ( res ) ;
13+
14+
15+ var codeText = File . ReadAllText ( @"./CSharp.Scripting.codetext.csx" ) ;
16+ codeText = codeText . Insert ( 0 , "using static Python.System;\r \n " ) ;
17+ var scriptOptions = ScriptOptions . Default
18+ . AddReferences ( typeof ( Python . System ) . Assembly ) ;
19+ scriptOptions . AddReferences ( typeof ( System . Math ) . Assembly ) ;
20+
21+ res = await CSharpScript . EvaluateAsync ( codeText , scriptOptions ) ;
22+ Console . WriteLine ( res ) ;
Original file line number Diff line number Diff line change 55![ Nuget] ( https://img.shields.io/nuget/dt/Python.System?style=for-the-badge )
66[ ![ GitHub release] ( https://img.shields.io/github/v/release/heartacker/Python.System?style=for-the-badge )] ( https://github.com/heartacker/Python.System/releases )
77
8+ - [ Roslyn] ( https://learn.microsoft.com/zh-cn/dotnet/api/?view=roslyn-dotnet-4.3.0 )
9+ - [ CSharpScript] ( https://blog.51cto.com/u_13267193/5552052 )
10+ - [ CSharpScript MemoryManager] ( https://blog.51cto.com/ineuos/4027860 )
11+ - [ Unity引擎与C#脚本] ( https://blog.51cto.com/u_15127597/4740392 )
12+ - [ Scripting-API-Samples] ( https://github.com/dotnet/roslyn/blob/main/docs/wiki/Scripting-API-Samples.md )
813<!-- @import "[TOC]" {cmd="toc" depthFrom=1 depthTo=6 orderedList=false} -->
914
1015<!-- code_chunk_output -->
You can’t perform that action at this time.
0 commit comments