. NET Scripts

Source: Internet
Author: User
Introduction to Scripts
You know what I did for the former. NET times have any nostalgia? Script! I like to create a small script file for me to do some minor tasks, or to test a small piece of code without creating a project or solution. I like to handle and erase just a small file instead of a solution folder, engineering folders and accompanying bin and obj folders. I miss those times and that's why I created the. NET script.

What is a. NET script? Basically, it's a simple console application that reads XML documents from the. dnml file (Dot net Markup Language, the. NET markup language, which I defined, haha). This XML document contains the following child elements, storing the assembly reference, the language in which the code is written, and the actual code to compile and execute. The console application, which I call the scripting engine, reads the XML text and analyzes the data that is needed. It then uses CSharp, VisualBasic, and classes in the CodeDom namespace to compile the code and mount the resulting assembly into memory. The textbooks engine uses the reflection mechanism to perform the entry function in the generated assembly. When the user closes the console window, the script engine is shut down, the assembly in memory will no longer exist, and it will be cleaned up by the garbage collector. There are no libraries or executable programs to generate.

Dot Net Markup Language
Let's see what the. NET markup language looks like. It's actually very simple. Here is an example of it. I'll explain each element of the XML document one by one.

<dnml>
<reference assembly= "System.Windows.Forms.dll"/>
<language name= "C #"/>
<scriptcode><! [cdata[
Using System.Windows.Forms;
public class Test
{
public static void Main ()
{
Console.WriteLine ("This is a Test");
MessageBox.Show ("This is another Test");
Test2 two = new Test2 ();
Two. Stuff ();
}
}
public class Test2
{
public void Stuff ()
{
Console.WriteLine ("Instance call");
}
}
]]></scriptcode>
</dnml>
<span


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.