php 网站301,造价师在哪个网站做继续教育,南京网站设计建设,营销微信管理类库你就新建类库文件直接生成dll去引用好了#xff0c;但是群友非要骚操作#xff0c;新建一个windows窗体把他搞成dll去引用#xff0c;当时我回答了这个问题是可以的#xff0c;但是实际上我没有这么干过#xff0c;今天恰好有空#xff0c;体验了一把#xff0c;的确… 类库你就新建类库文件直接生成dll去引用好了但是群友非要骚操作新建一个windows窗体把他搞成dll去引用当时我回答了这个问题是可以的但是实际上我没有这么干过今天恰好有空体验了一把的确可以。首先说明哈因为这只是测试这么个功能我新建的项目名字以及窗体名字都没改偷懒了哈网友勿喷先新建第一个窗体应用代码如下using Microsoft.CSharp;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace WindowsFormsApp12
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){}private void button1_Click(object sender, EventArgs e){MessageBox.Show(GetCode2());}public static string GetCode2(){StringBuilder sb new StringBuilder();sb.Append(using System;);sb.Append(Environment.NewLine);sb.Append(namespace DynamicCodeGenerate);sb.Append(Environment.NewLine);sb.Append({);sb.Append(Environment.NewLine);sb.Append( public class HelloWorld);sb.Append(Environment.NewLine);sb.Append( {);sb.Append(Environment.NewLine);sb.Append( public string OutPut());sb.Append(Environment.NewLine);sb.Append( {);sb.Append(Environment.NewLine);sb.Append( return \Hello world!\;);sb.Append(Environment.NewLine);sb.Append( });sb.Append(Environment.NewLine);sb.Append( });sb.Append(Environment.NewLine);sb.Append(});string code sb.ToString();return code;}}
}点击按钮运行后结果如下然后我把它的输出类型改为类库然后去新建第二个窗体应用然后引用上面的项目代码如下using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApp12;namespace WindowsFormsApp1
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){//WindowsFormsApp12.Form1 f1 new WindowsFormsApp12.Form1();MessageBox.Show( WindowsFormsApp12.Form1.GetCode2());}}
}执行后源码链接: https://pan.baidu.com/s/1uWegVTHc2guz7FaQ5j8WIA 提取码: g7fp