Waht是Roslyn API(执行)? [英] Waht is Roslyn API (execute)?
本文介绍了Waht是Roslyn API(执行)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
添加到我之前提出的问题:
如何使用ASP.Net Web表单中的Roslyn执行C#代码?
我想了解Roslyn API(执行)。
应该如何输入和输出。
我解释说我在C#中使用控制台应用程序尝试它然而当我使用构建GUI时它可以工作ASP .Net Web表单应用程序它处理错误(NullReferenceException)。
如何找到执行API的代码?
这是代码:
Adding to the previous questions I have asked:
How I can execute C# code using Roslyn in ASP.Net web form?
I want to know about Roslyn API ( execute ).
how should its input should be and waht's the output.
Preiously I explained that I try it with the console application in C# and it works however when I build the GUI using ASP .Net web form application it handle an error (NullReferenceException).
How could I find the code of execute API?
This is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using Roslyn.Scripting;
using Roslyn.Scripting.CSharp;
using Roslyn.Compilers;
using Roslyn.Compilers.CSharp;
using System.IO;
namespace WebApplication2
{
public partial class _Default : Page
{
//private object result = new object();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button_Click(object sender, EventArgs e)
{
String code = TextBox3.Text;
var ScriptEngine = new ScriptEngine();
var session = ScriptEngine.CreateSession();
try
{
session.AddReference("System");
session.AddReference("System.core");
object result = session.Execute(code);
TextBox2.Text = result.ToString();
}
catch (System.NullReferenceException err)
{
TextBox2.Text = err.Message;
}
}
}
}
推荐答案
这不是一件小事,下次你应该做好功课。
就像我现在的懒惰一样,我在不到一分钟的时间里找到了谷歌的帮助!
阅读:
Roslyn Scripting API简介
使用Roslyn Scripting API in C#
和
C#作为.NET应用程序中使用Roslyn的脚本语言,由我们的编码员编写。
This is not trivial stuff and you should do you homework better next time.
As lazy as I am at this moment I have found this in under a minute with little help from Google!
Read this:
Introduction to the Roslyn Scripting API
Using The Roslyn Scripting API in C#
and
C# as a Scripting Language in Your .NET Applications Using Roslyn by our fellow coder.
这篇关于Waht是Roslyn API(执行)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文