Siegfried Pammer 3 months ago
parent
commit
85f704dd89
  1. 2
      ILSpy/Controls/TreeView/SharpTreeView.xaml
  2. 71
      ILSpy/ViewModels/CompareViewModel.cs

2
ILSpy/Controls/TreeView/SharpTreeView.xaml

@ -246,7 +246,7 @@
VerticalAlignment="Center" /> VerticalAlignment="Center" />
</Border> </Border>
<StackPanel Orientation="Horizontal" <StackPanel Orientation="Horizontal"
Background="Transparent" Background="{Binding Background}"
ToolTip="{Binding ToolTip}"> ToolTip="{Binding ToolTip}">
<ContentPresenter Name="icon" <ContentPresenter Name="icon"
Content="{Binding Icon}" Content="{Binding Icon}"

71
ILSpy/ViewModels/CompareViewModel.cs

@ -15,6 +15,7 @@ using TomsToolbox.Wpf;
namespace ICSharpCode.ILSpy.ViewModels namespace ICSharpCode.ILSpy.ViewModels
{ {
using System.Linq; using System.Linq;
using System.Windows.Media;
using ICSharpCode.Decompiler; using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
@ -90,6 +91,7 @@ namespace ICSharpCode.ILSpy.ViewModels
{ {
var m = new Entry() { var m = new Entry() {
Entity = a.Entity, Entity = a.Entity,
OtherEntity = b.Entity,
Signature = a.Signature, Signature = a.Signature,
}; };
@ -367,12 +369,14 @@ namespace ICSharpCode.ILSpy.ViewModels
get { get {
if (kind != null) if (kind != null)
return kind.Value; return kind.Value;
if (Children == null)
return DiffKind.None;
int addCount = 0, removeCount = 0, updateCount = 0; int addCount = 0, removeCount = 0, updateCount = 0;
foreach (var item in Children) foreach (var item in Children)
{ {
switch (item.Kind) switch (item.RecursiveKind)
{ {
case DiffKind.Add: case DiffKind.Add:
addCount++; addCount++;
@ -396,16 +400,20 @@ namespace ICSharpCode.ILSpy.ViewModels
} }
} }
public DiffKind Kind { get; set; } public DiffKind Kind {
get => this.kind ?? DiffKind.None;
set => this.kind = value;
}
public required string Signature { get; init; } public required string Signature { get; init; }
public required ISymbol Entity { get; init; } public required ISymbol Entity { get; init; }
public ISymbol? OtherEntity { get; init; }
public Entry? Parent { get; set; } public Entry? Parent { get; set; }
public List<Entry>? Children { get; set; } public List<Entry>? Children { get; set; }
private string GetDebuggerDisplay() private string GetDebuggerDisplay()
{ {
return $"Entry{Kind}{Entity?.ToString() ?? Signature}"; return $"Entry{Kind}{Entity.ToString() ?? Signature}";
} }
} }
@ -447,7 +455,7 @@ namespace ICSharpCode.ILSpy.ViewModels
if (entry.Children == null) if (entry.Children == null)
return; return;
foreach (var item in entry.Children) foreach (var item in entry.Children.OrderBy(e => (-(int)e.RecursiveKind, e.Entity.SymbolKind, e.Signature)))
{ {
this.Children.Add(new ComparisonEntryTreeNode(item)); this.Children.Add(new ComparisonEntryTreeNode(item));
} }
@ -455,25 +463,21 @@ namespace ICSharpCode.ILSpy.ViewModels
public override object Text { public override object Text {
get { get {
switch (entry.Entity) string? entityText = GetEntityText(entry.Entity);
{ string? otherText = GetEntityText(entry.OtherEntity);
case ITypeDefinition t:
return this.Language.TypeToString(t, includeNamespace: false) + GetSuffixString(t.MetadataToken); return entityText + (otherText != null && ? " -> " + otherText : "");
case IMethod m:
return this.Language.MethodToString(m, false, false, false) + GetSuffixString(m.MetadataToken); string? GetEntityText(ISymbol? symbol) => symbol switch {
case IField f: ITypeDefinition t => this.Language.TypeToString(t, includeNamespace: false) + GetSuffixString(t.MetadataToken),
return this.Language.FieldToString(f, false, false, false) + GetSuffixString(f.MetadataToken); IMethod m => this.Language.MethodToString(m, false, false, false) + GetSuffixString(m.MetadataToken),
case IProperty p: IField f => this.Language.FieldToString(f, false, false, false) + GetSuffixString(f.MetadataToken),
return this.Language.PropertyToString(p, false, false, false) + GetSuffixString(p.MetadataToken); IProperty p => this.Language.PropertyToString(p, false, false, false) + GetSuffixString(p.MetadataToken),
case IEvent e: IEvent e => this.Language.EventToString(e, false, false, false) + GetSuffixString(e.MetadataToken),
return this.Language.EventToString(e, false, false, false) + GetSuffixString(e.MetadataToken); INamespace n => n.FullName,
case INamespace n: IModule m => m.FullAssemblyName,
return n.FullName; _ => null,
case IModule m: };
return m.FullAssemblyName;
default:
return entry.Signature;
}
} }
} }
@ -501,11 +505,6 @@ namespace ICSharpCode.ILSpy.ViewModels
} }
} }
public DiffKind RecursiveKind => entry.RecursiveKind;
public DiffKind Kind => entry.Kind;
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{ {
} }
@ -514,5 +513,21 @@ namespace ICSharpCode.ILSpy.ViewModels
//{ //{
// return RecursiveKind != DiffKind.None ? FilterResult.Match : FilterResult.Hidden; // return RecursiveKind != DiffKind.None ? FilterResult.Match : FilterResult.Hidden;
//} //}
public Brush Background {
get {
switch (entry.RecursiveKind)
{
case DiffKind.Add:
return Brushes.LightGreen;
case DiffKind.Remove:
return Brushes.LightPink;
case DiffKind.Update:
return Brushes.LightBlue;
}
return Brushes.Transparent;
}
}
} }
} }

Loading…
Cancel
Save