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); } }
尋找差異