📄 complie.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Reflection;
using System.Text.RegularExpressions;
namespace RegexTool
{
/// <summary>
/// Complie 的摘要说明。
/// </summary>
public class Complie : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox txtDll;
private System.Windows.Forms.TextBox txtNamespace;
private System.Windows.Forms.TextBox txtRegex;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public TextBox txtReg;
public Complie()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Complie));
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.txtDll = new System.Windows.Forms.TextBox();
this.txtNamespace = new System.Windows.Forms.TextBox();
this.txtRegex = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 20);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(76, 23);
this.label1.TabIndex = 0;
this.label1.Text = "dll文件名:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 23);
this.label2.TabIndex = 1;
this.label2.Text = "名称空间:";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 96);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(112, 23);
this.label3.TabIndex = 2;
this.label3.Text = "正则表达式名称:";
//
// txtDll
//
this.txtDll.BackColor = System.Drawing.SystemColors.Control;
this.txtDll.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtDll.Location = new System.Drawing.Point(120, 16);
this.txtDll.Name = "txtDll";
this.txtDll.TabIndex = 3;
this.txtDll.Text = "";
//
// txtNamespace
//
this.txtNamespace.BackColor = System.Drawing.SystemColors.Control;
this.txtNamespace.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtNamespace.Location = new System.Drawing.Point(120, 52);
this.txtNamespace.Name = "txtNamespace";
this.txtNamespace.TabIndex = 4;
this.txtNamespace.Text = "";
//
// txtRegex
//
this.txtRegex.BackColor = System.Drawing.SystemColors.Control;
this.txtRegex.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtRegex.Location = new System.Drawing.Point(120, 92);
this.txtRegex.Name = "txtRegex";
this.txtRegex.TabIndex = 5;
this.txtRegex.Text = "";
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button1.Location = new System.Drawing.Point(76, 136);
this.button1.Name = "button1";
this.button1.TabIndex = 6;
this.button1.Text = "编译";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Complie
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(252, 173);
this.Controls.Add(this.button1);
this.Controls.Add(this.txtRegex);
this.Controls.Add(this.txtNamespace);
this.Controls.Add(this.txtDll);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Complie";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "编译选项";
this.TopMost = true;
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 编译正则表达式事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e)
{
try
{
//得到正则表式内容,名称。
string strRegex = txtReg.Text;
string strDll = txtDll.Text;
string strNS = txtNamespace.Text;
string strRegexName = txtRegex.Text;
if ( strDll!="" && strNS!="" && strRegex!="" )
{
//进行编译
RegexCompilationInfo[] rci = new RegexCompilationInfo[1];
rci[0] = new RegexCompilationInfo( strRegex, RegexOptions.Compiled, strRegexName, strNS, true );
AssemblyName an = new AssemblyName();
an.Name = @strDll;
Regex.CompileToAssembly( rci, an );
MessageBox.Show("编译成功!");
}
else
{
MessageBox.Show("各个名称必须添写!","名称没有添!");
}
}
catch ( Exception eeee )
{
MessageBox.Show( eeee.Message.ToString() );
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -