Diff
checker
Text
Text
Images
Documents
Excel
Folders
Legal
Enterprise
Desktop
Pricing
Sign in
Download Diffchecker Desktop
Compare text
Find the difference between two text files
Tools
History
Real-time editor
Hide whitespace changes
Hide unchanged lines
Disable line wrap
Layout
Split
Unified
Diff precision
Smart
Word
Char
Text styles
Change appearance
Syntax highlighting
Choose syntax
Ignore
Transform text
Go to first change
Edit input
Diffchecker Desktop
The most secure way to run Diffchecker. Get the Diffchecker Desktop app: your diffs never leave your computer!
Get Desktop
Untitled diff
Created
8 years ago
Diff never expires
Clear
Export
Share
Explain
3 removals
Lines
Total
Removed
Characters
Total
Removed
To continue using this feature, upgrade to
Diff
checker
Pro
View Pricing
52 lines
Copy
17 additions
Lines
Total
Added
Characters
Total
Added
To continue using this feature, upgrade to
Diff
checker
Pro
View Pricing
60 lines
Copy
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()
{
{
Copy
Copied
Copy
Copied
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);
Copy
Copied
Copy
Copied
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,
Copy
Copied
Copy
Copied
syntaxTrees: new[] { tree }, references: new[] { mscorlib }
);
syntaxTrees: new[] { tree }, references: new[] { mscorlib }
, options: options
);
Copy
Copied
Copy
Copied
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}")));
}
}
Copy
Copied
Copy
Copied
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);
Copy
Copied
Copy
Copied
ms.Close();
return () => meth.Invoke(null, null);
return () => meth.Invoke(null, null);
}
}
}
}
Saved diffs
Original text
Open file
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); } }
Changed text
Open file
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); } }
Find difference