зеркало из https://github.com/dotnet/roslyn.git
Updated Scripting API Samples (markdown)
Родитель
0ca249df9a
Коммит
fd363ed02c
|
@ -70,7 +70,7 @@ Console.WriteLine(await CSharpScript.EvaluateAsync<int>("X+Y", globals: globals)
|
||||||
### <a name="multi"></a> Create & build a C# script and execute it multiple times
|
### <a name="multi"></a> Create & build a C# script and execute it multiple times
|
||||||
```csharp
|
```csharp
|
||||||
var script = CSharpScript.Create<int>("X*Y", globalsType: typeof(Globals));
|
var script = CSharpScript.Create<int>("X*Y", globalsType: typeof(Globals));
|
||||||
script.Build();
|
script.Compile();
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
Console.WriteLine(await script.EvaluateAsync(new Globals { X = i, Y = i }));
|
Console.WriteLine(await script.EvaluateAsync(new Globals { X = i, Y = i }));
|
||||||
|
@ -117,6 +117,7 @@ Console.WriteLine(state.ReturnValue);
|
||||||
### <a name="createscript"></a> Create and analyze a C# script
|
### <a name="createscript"></a> Create and analyze a C# script
|
||||||
```csharp
|
```csharp
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
|
|
||||||
var script = CSharpScript.Create<int>(Console.ReadLine());
|
var script = CSharpScript.Create<int>(Console.ReadLine());
|
||||||
Compilation compilation = script.GetCompilation();
|
Compilation compilation = script.GetCompilation();
|
||||||
//do stuff
|
//do stuff
|
||||||
|
@ -126,6 +127,7 @@ Compilation gives access to the full set of Roslyn APIs.
|
||||||
### <a name="assembly"></a> Customize assembly loading
|
### <a name="assembly"></a> Customize assembly loading
|
||||||
```csharp
|
```csharp
|
||||||
using Microsoft.CodeAnalysis.Scripting.Hosting;
|
using Microsoft.CodeAnalysis.Scripting.Hosting;
|
||||||
|
|
||||||
using (var loader = new InteractiveAssemblyLoader())
|
using (var loader = new InteractiveAssemblyLoader())
|
||||||
{
|
{
|
||||||
var script = CSharpScript.Create<int>("1", assemblyLoader: loader);
|
var script = CSharpScript.Create<int>("1", assemblyLoader: loader);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче