在采用reflector反编译代码的时候,字符串都被转换成unicode形式保存
从网上查了一些资料,基本都是采用内码的办法进行转换
其实可以采用很简单的办法解决,就是通过CodeDom的方法
代码如下:
从网上查了一些资料,基本都是采用内码的办法进行转换
其实可以采用很简单的办法解决,就是通过CodeDom的方法
代码如下:
1
CodeDomProvider prov = new CSharpCodeProvider();
2
CompilerParameters para = new CompilerParameters();
6
para.GenerateInMemory = true;
7
para.TreatWarningsAsErrors = false;
8
string code =
9
"namespace My{ " +
10
"public class Code " +
11
"{" +
12
" public string GetString()" +
13
" {" +
14
" string strCode = \"" + textBox1.Text + "\";" + //形式如:\u8bf7\u5148\u5b9a
15
" return strCode;" +
16
" }" +
17
"}}";
19
CompilerResults cr = prov.CompileAssemblyFromSource(para, code);
20
foreach (string s in cr.Output) {
21
System.Diagnostics.Debug.WriteLine(s);
22
}
23
24
Assembly assembly = cr.CompiledAssembly;
25
Type type = assembly.GetType("My.Code");
26
object obj = assembly.CreateInstance("My.Code");
27
string ret = type.InvokeMember("GetString", BindingFlags.InvokeMethod, null, obj, null).ToString();
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/None.gif)
10
![](/Images/OutliningIndicators/None.gif)
11
![](/Images/OutliningIndicators/None.gif)
12
![](/Images/OutliningIndicators/None.gif)
13
![](/Images/OutliningIndicators/None.gif)
14
![](/Images/OutliningIndicators/None.gif)
15
![](/Images/OutliningIndicators/None.gif)
16
![](/Images/OutliningIndicators/None.gif)
17
![](/Images/OutliningIndicators/None.gif)
19
![](/Images/OutliningIndicators/None.gif)
20
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
21
![](/Images/OutliningIndicators/InBlock.gif)
22
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
23
![](/Images/OutliningIndicators/None.gif)
24
![](/Images/OutliningIndicators/None.gif)
25
![](/Images/OutliningIndicators/None.gif)
26
![](/Images/OutliningIndicators/None.gif)
27
![](/Images/OutliningIndicators/None.gif)