2014-04-16 12 views
5

Ich möchte Unterschiede zwischen zwei Dateien in asp.net hervorheben. Nach der Websuche habe ich Diffplex APi gewählt. Ich bin ein Anfänger. Ich brauche eine Anleitung, wie man es umsetzen kann? Ich habe die Referenzbibliotheken hinzugefügt und das ist alles, was ich verstehen konnte. Es gibt keine Dokumentation der Api. Ich habe Apis vorher noch nicht benutzt.Erste Schritte mit Diffplex

Antwort

6

Hier ist ein einfaches Beispiel aus der "Dokumentation" (d. H. Der Quellcode), mit dem Sie beginnen sollten.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using DiffPlex; 
using DiffPlex.DiffBuilder; 
using DiffPlex.DiffBuilder.Model; 
using System.Text; 


namespace DiffPlexTest.Controllers 
{ 
    public class HomeController : Controller 
    { 
     public ActionResult Index() 
     { 
      StringBuilder sb = new StringBuilder(); 

      string oldText = @"We the people 
       of the united states of america 
       establish justice 
       ensure domestic tranquility 
       provide for the common defence 
       secure the blessing of liberty 
       to ourselves and our posterity"; 
      string newText = @"We the peaple 
       in order to form a more perfect union 
       establish justice 
       ensure domestic tranquility 
       promote the general welfare and 
       secure the blessing of liberty 
       to ourselves and our posterity 
       do ordain and establish this constitution 
       for the United States of America"; 

      var d = new Differ(); 
      var builder = new InlineDiffBuilder(d); 
      var result = builder.BuildDiffModel(oldText, newText); 

      foreach (var line in result.Lines) 
      { 
       if (line.Type == ChangeType.Inserted) 
       { 
        sb.Append("+ "); 
       } 
       else if (line.Type == ChangeType.Deleted) 
       { 
        sb.Append("- "); 
       } 
       else if (line.Type == ChangeType.Modified) 
       { 
        sb.Append("* "); 
       } 
       else if (line.Type == ChangeType.Imaginary) 
       { 
        sb.Append("? "); 
       } 
       else if (line.Type == ChangeType.Unchanged) 
       { 
        sb.Append(" "); 
       } 

       sb.Append(line.Text + "<br/>"); 
      } 

      ViewData["old"] = oldText; 
      ViewData["new"] = newText; 
      ViewData["result"] = sb.ToString(); 

      return View(); 
     } 
    } 
} 
+0

Danke, genau das, was ich für – JanR

+2

Great suchen - baute ich ein Diff-Tool auf der DiffPlex, die ziemlich gut funktioniert, so denke ich, Sie mit ihm viel Glück haben werden. –

+0

Hat Diffplex eine native Zusammenführungsoption? – JanR