Diff
checker
文本
文本
图像
文档
Excel
文件夹
Legal
Enterprise
桌面版
定价
登录
下载 Diffchecker 桌面版
比较文本
查找两个文本文件之间的差异
工具
历史
实时编辑器
隐藏空白更改
折叠未更改行
关闭换行
视图
拆分
统一
比对精度
智能
单词
字符
文本样式
更改外观
语法高亮
选择语法
忽略
文本转换
转到第一个差异
编辑输入
Diffchecker Desktop
运行Diffchecker最安全的方式。获取Diffchecker桌面应用:您的差异永远不会离开您的电脑!
获取桌面版
Untitled diff
创建于
8年前
差异永不过期
清除
导出
分享
解释
3 删除
行
总计
删除
字符
总计
删除
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
52 行
全部复制
17 添加
行
总计
添加
字符
总计
添加
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
60 行
全部复制
using System;
using System;
using System.IO;
using System.IO;
using System.Linq;
using System.Linq;
using System.Reflection;
using System.Reflection;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp;
class Program
class Program
{
{
static void Main(string[] args)
static void Main(string[] args)
{
{
var greetings = HelloWorlder.GetGreetings();
var greetings = HelloWorlder.GetGreetings();
// should write Hello World
// should write Hello World
greetings();
greetings();
}
}
}
}
public static class HelloWorlder
public static class HelloWorlder
{
{
public static Action GetGreetings()
public static Action GetGreetings()
{
{
var tree = CSharpSyntaxTree.ParseText(@"
var tree = CSharpSyntaxTree.ParseText(@"
using System;
using System;
public class MyClass
public class MyClass
{
{
public static void Main()
public static void Main()
{
{
复制
已复制
复制
已复制
Console.WriteLine(""Hello World!"");
//
Console.WriteLine(""Hello World!"");
Console.ReadLine();
//
Console.ReadLine();
}
}
}");
}");
const string testAsmName = "testLib";
const string testAsmName = "testLib";
var coreDir = Path.GetDirectoryName(typeof(object).GetTypeInfo().Assembly.Location);
var coreDir = Path.GetDirectoryName(typeof(object).GetTypeInfo().Assembly.Location);
复制
已复制
复制
已复制
var mscorlib = MetadataReference.CreateFromFile(Path.Combine(coreDir, "
mscorlib
.dll"));
var mscorlib = MetadataReference.CreateFromFile(Path.Combine(coreDir, "
System.Private.CoreLib
.dll"));
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
var compilation = CSharpCompilation.Create(testAsmName,
var compilation = CSharpCompilation.Create(testAsmName,
复制
已复制
复制
已复制
syntaxTrees: new[] { tree }, references: new[] { mscorlib }
);
syntaxTrees: new[] { tree }, references: new[] { mscorlib }
, options: options
);
复制
已复制
复制
已复制
var emitResult = compilation.Emit(
$"{testAsmName}.dll"
);
var ms = new MemoryStream();
var emitResult = compilation.Emit(
ms);
ms.Seek(0, SeekOrigin.Begin
);
if (!emitResult.Success)
if (!emitResult.Success)
{
{
throw new Exception(string.Join(Environment.NewLine, emitResult.Diagnostics.Select((x, i) => $"{i + 1}. {x}")));
throw new Exception(string.Join(Environment.NewLine, emitResult.Diagnostics.Select((x, i) => $"{i + 1}. {x}")));
}
}
复制
已复制
复制
已复制
var ourAssembly = Assembly.Load(
new AssemblyName(testAsmName
));
var ourAssembly = Assembly.Load(
ms.ToArray(
));
var type = ourAssembly.GetType("MyClass");
var type = ourAssembly.GetType("MyClass");
var meth = type.GetRuntimeMethod("Main", Type.EmptyTypes);
var meth = type.GetRuntimeMethod("Main", Type.EmptyTypes);
复制
已复制
复制
已复制
ms.Close();
return () => meth.Invoke(null, null);
return () => meth.Invoke(null, null);
}
}
}
}
已保存差异
原始文本
打开文件
using System; using System.IO; using System.Linq; using System.Reflection; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; class Program { static void Main(string[] args) { var greetings = HelloWorlder.GetGreetings(); // should write Hello World greetings(); } } public static class HelloWorlder { public static Action GetGreetings() { var tree = CSharpSyntaxTree.ParseText(@" using System; public class MyClass { public static void Main() { Console.WriteLine(""Hello World!""); Console.ReadLine(); } }"); const string testAsmName = "testLib"; var coreDir = Path.GetDirectoryName(typeof(object).GetTypeInfo().Assembly.Location); var mscorlib = MetadataReference.CreateFromFile(Path.Combine(coreDir, "mscorlib.dll")); var compilation = CSharpCompilation.Create(testAsmName, syntaxTrees: new[] { tree }, references: new[] { mscorlib }); var emitResult = compilation.Emit($"{testAsmName}.dll"); if (!emitResult.Success) { throw new Exception(string.Join(Environment.NewLine, emitResult.Diagnostics.Select((x, i) => $"{i + 1}. {x}"))); } var ourAssembly = Assembly.Load(new AssemblyName(testAsmName)); var type = ourAssembly.GetType("MyClass"); var meth = type.GetRuntimeMethod("Main", Type.EmptyTypes); return () => meth.Invoke(null, null); } }
更改后文本
打开文件
using System; using System.IO; using System.Linq; using System.Reflection; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; class Program { static void Main(string[] args) { var greetings = HelloWorlder.GetGreetings(); // should write Hello World greetings(); } } public static class HelloWorlder { public static Action GetGreetings() { var tree = CSharpSyntaxTree.ParseText(@" using System; public class MyClass { public static void Main() { //Console.WriteLine(""Hello World!""); //Console.ReadLine(); } }"); const string testAsmName = "testLib"; var coreDir = Path.GetDirectoryName(typeof(object).GetTypeInfo().Assembly.Location); var mscorlib = MetadataReference.CreateFromFile(Path.Combine(coreDir, "System.Private.CoreLib.dll")); var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); var compilation = CSharpCompilation.Create(testAsmName, syntaxTrees: new[] { tree }, references: new[] { mscorlib }, options: options); var ms = new MemoryStream(); var emitResult = compilation.Emit(ms); ms.Seek(0, SeekOrigin.Begin); if (!emitResult.Success) { throw new Exception(string.Join(Environment.NewLine, emitResult.Diagnostics.Select((x, i) => $"{i + 1}. {x}"))); } var ourAssembly = Assembly.Load(ms.ToArray()); var type = ourAssembly.GetType("MyClass"); var meth = type.GetRuntimeMethod("Main", Type.EmptyTypes); ms.Close(); return () => meth.Invoke(null, null); } }
查找差异