Skip to content

Commit

Permalink
Proof out the changes necessary for making SharpTreeNode cross platfo…
Browse files Browse the repository at this point in the history
…rm by proxying System.Windows dependencies
  • Loading branch information
christophwille committed Jul 22, 2024
1 parent aa91405 commit 4bd46c4
Show file tree
Hide file tree
Showing 27 changed files with 5,112 additions and 4,955 deletions.
374 changes: 187 additions & 187 deletions ICSharpCode.Decompiler.Tests/TestCases/Correctness/OverloadResolution.cs

Large diffs are not rendered by default.

8,612 changes: 4,306 additions & 4,306 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/CompoundAssignmentTest.cs

Large diffs are not rendered by default.

740 changes: 370 additions & 370 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/DynamicTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ public ref readonly int M2(ref readonly int x)
return ref x;
}

public void Test()
{
int x = 32;
M(in x);
M2(in x);
}
#endif
public void Test()
{
int x = 32;
M(in x);
M2(in x);
}
#endif
}
}
18 changes: 9 additions & 9 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/ValueTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,14 @@ public static void AcceptRefReadOnly(ref readonly S o)
{
}

private static void Use(in S param)
{
AcceptIn(new S(5));
S o = new S(10);
AcceptRefReadOnly(in o);
AcceptIn(in param);
AcceptRefReadOnly(in param);
}
#endif
private static void Use(in S param)
{
AcceptIn(new S(5));
S o = new S(10);
AcceptRefReadOnly(in o);
AcceptIn(in param);
AcceptRefReadOnly(in param);
}
#endif
}
}
76 changes: 38 additions & 38 deletions ICSharpCode.ILSpyX/Analyzers/AnalyzerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,49 +34,49 @@ public class AnalyzerContext
{
public required AssemblyList AssemblyList { get; init; }

/// <summary>
/// CancellationToken. Currently Analyzers do not support cancellation from the UI, but it should be checked nonetheless.
/// </summary>
public CancellationToken CancellationToken { get; init; }
/// <summary>
/// CancellationToken. Currently Analyzers do not support cancellation from the UI, but it should be checked nonetheless.
/// </summary>
public CancellationToken CancellationToken { get; init; }

/// <summary>
/// Currently used language.
/// </summary>
public required ILanguage Language { get; init; }
/// <summary>
/// Currently used language.
/// </summary>
public required ILanguage Language { get; init; }

/// <summary>
/// Allows the analyzer to control whether the tree nodes will be sorted.
/// Must be set within <see cref="IAnalyzer.Analyze(ISymbol, AnalyzerContext)"/>
/// before the results are enumerated.
/// </summary>
public bool SortResults { get; set; }
/// <summary>
/// Allows the analyzer to control whether the tree nodes will be sorted.
/// Must be set within <see cref="IAnalyzer.Analyze(ISymbol, AnalyzerContext)"/>
/// before the results are enumerated.
/// </summary>
public bool SortResults { get; set; }

public MethodBodyBlock? GetMethodBody(IMethod method)
{
if (!method.HasBody || method.MetadataToken.IsNil || method.ParentModule?.MetadataFile == null)
return null;
var module = method.ParentModule.MetadataFile;
var md = module.Metadata.GetMethodDefinition((MethodDefinitionHandle)method.MetadataToken);
try
{
return module.GetMethodBody(md.RelativeVirtualAddress);
}
catch (BadImageFormatException)
{
return null;
}
}
public MethodBodyBlock? GetMethodBody(IMethod method)
{
if (!method.HasBody || method.MetadataToken.IsNil || method.ParentModule?.MetadataFile == null)
return null;
var module = method.ParentModule.MetadataFile;
var md = module.Metadata.GetMethodDefinition((MethodDefinitionHandle)method.MetadataToken);
try
{
return module.GetMethodBody(md.RelativeVirtualAddress);
}
catch (BadImageFormatException)
{
return null;
}
}

public AnalyzerScope GetScopeOf(IEntity entity)
{
return new AnalyzerScope(AssemblyList, entity);
}
public AnalyzerScope GetScopeOf(IEntity entity)
{
return new AnalyzerScope(AssemblyList, entity);
}

readonly ConcurrentDictionary<MetadataFile, DecompilerTypeSystem> typeSystemCache = new();
readonly ConcurrentDictionary<MetadataFile, DecompilerTypeSystem> typeSystemCache = new();

public DecompilerTypeSystem GetOrCreateTypeSystem(MetadataFile module)
{
return typeSystemCache.GetOrAdd(module, m => new DecompilerTypeSystem(m, m.GetAssemblyResolver()));
}
public DecompilerTypeSystem GetOrCreateTypeSystem(MetadataFile module)
{
return typeSystemCache.GetOrAdd(module, m => new DecompilerTypeSystem(m, m.GetAssemblyResolver()));
}
}
}
3 changes: 2 additions & 1 deletion ILSpy/Analyzers/AnalyzerEntityTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpyX;
using ICSharpCode.TreeView;
using ICSharpCode.TreeView.PlatformAbstractions;

namespace ICSharpCode.ILSpy.Analyzers
{
Expand All @@ -33,7 +34,7 @@ public abstract class AnalyzerEntityTreeNode : AnalyzerTreeNode, IMemberTreeNode
{
public abstract IEntity Member { get; }

public override void ActivateItem(System.Windows.RoutedEventArgs e)
public override void ActivateItem(IPlatformRoutedEventArgs e)
{
e.Handled = true;
if (this.Member == null || this.Member.MetadataToken.IsNil)
Expand Down
3 changes: 2 additions & 1 deletion ILSpy/Analyzers/TreeNodes/AnalyzedModuleTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpyX.Analyzers;
using ICSharpCode.TreeView.PlatformAbstractions;

namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
{
Expand Down Expand Up @@ -52,7 +53,7 @@ protected override void LoadChildren()
}
}

public override void ActivateItem(RoutedEventArgs e)
public override void ActivateItem(IPlatformRoutedEventArgs e)
{
e.Handled = true;
if (analyzedModule.MetadataFile == null)
Expand Down
9 changes: 5 additions & 4 deletions ILSpy/TreeNodes/AssemblyListTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using ICSharpCode.Decompiler.Util;
using ICSharpCode.ILSpyX;
using ICSharpCode.TreeView;
using ICSharpCode.TreeView.PlatformAbstractions;

namespace ICSharpCode.ILSpy.TreeNodes
{
Expand Down Expand Up @@ -81,21 +82,21 @@ void BindToObservableCollection(AssemblyList collection)
};
}

public override bool CanDrop(DragEventArgs e, int index)
public override bool CanDrop(IPlatformDragEventArgs e, int index)
{
e.Effects = DragDropEffects.Move | DragDropEffects.Copy | DragDropEffects.Link;
e.Effects = XPlatDragDropEffects.Move | XPlatDragDropEffects.Copy | XPlatDragDropEffects.Link;
if (e.Data.GetDataPresent(AssemblyTreeNode.DataFormat))
return true;
else if (e.Data.GetDataPresent(DataFormats.FileDrop))
return true;
else
{
e.Effects = DragDropEffects.None;
e.Effects = XPlatDragDropEffects.None;
return false;
}
}

public override void Drop(DragEventArgs e, int index)
public override void Drop(IPlatformDragEventArgs e, int index)
{
string[] files = e.Data.GetData(AssemblyTreeNode.DataFormat) as string[];
if (files == null)
Expand Down
3 changes: 2 additions & 1 deletion ILSpy/TreeNodes/AssemblyReferenceTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.TreeView.PlatformAbstractions;

namespace ICSharpCode.ILSpy.TreeNodes
{
Expand Down Expand Up @@ -66,7 +67,7 @@ public override bool ShowExpander {
}
}

public override void ActivateItem(System.Windows.RoutedEventArgs e)
public override void ActivateItem(IPlatformRoutedEventArgs e)
{
if (parentAssembly.Parent is AssemblyListTreeNode assemblyListNode)
{
Expand Down
10 changes: 6 additions & 4 deletions ILSpy/TreeNodes/AssemblyTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
using ICSharpCode.ILSpyX.FileLoaders;
using ICSharpCode.ILSpyX.PdbProvider;
using ICSharpCode.TreeView;
using ICSharpCode.TreeView.PlatformAbstractions;
using ICSharpCode.TreeView.PlatformAbstractions.WpfWindows;

using Microsoft.Win32;

Expand Down Expand Up @@ -410,9 +412,9 @@ public override bool CanDrag(SharpTreeNode[] nodes)
return nodes.All(n => n is AssemblyTreeNode { PackageEntry: null });
}

public override void StartDrag(DependencyObject dragSource, SharpTreeNode[] nodes)
public override void StartDrag(object dragSource, SharpTreeNode[] nodes, IPlatformDragDrop dragdropManager)
{
DragDrop.DoDragDrop(dragSource, Copy(nodes), DragDropEffects.All);
dragdropManager.DoDragDrop(dragSource, Copy(nodes), XPlatDragDropEffects.All);
}

public override bool CanDelete()
Expand All @@ -433,9 +435,9 @@ public override void DeleteCore()

internal const string DataFormat = "ILSpyAssemblies";

public override IDataObject Copy(SharpTreeNode[] nodes)
public override IPlatformDataObject Copy(SharpTreeNode[] nodes)
{
DataObject dataObject = new DataObject();
var dataObject = new WpfWindowsDataObject(new DataObject());
dataObject.SetData(DataFormat, nodes.OfType<AssemblyTreeNode>().Select(n => n.LoadedAssembly.FileName).ToArray());
return dataObject;
}
Expand Down
3 changes: 2 additions & 1 deletion ILSpy/TreeNodes/BaseTypesEntryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.TreeView;
using ICSharpCode.TreeView.PlatformAbstractions;

namespace ICSharpCode.ILSpy.TreeNodes
{
Expand All @@ -37,7 +38,7 @@ public BaseTypesEntryNode(ITypeDefinition type)

public override object Icon => type.Kind == TypeKind.Interface ? Images.Interface : Images.Class;

public override void ActivateItem(System.Windows.RoutedEventArgs e)
public override void ActivateItem(IPlatformRoutedEventArgs e)
{
e.Handled = ActivateItem(this, type);
}
Expand Down
3 changes: 2 additions & 1 deletion ILSpy/TreeNodes/DerivedTypesEntryNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace ICSharpCode.ILSpy.TreeNodes
{
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.TreeView.PlatformAbstractions;

class DerivedTypesEntryNode : ILSpyTreeNode, IMemberTreeNode
{
Expand Down Expand Up @@ -89,7 +90,7 @@ IEnumerable<ILSpyTreeNode> FetchChildren(CancellationToken ct)
return DerivedTypesTreeNode.FindDerivedTypes(list, type, ct);
}

public override void ActivateItem(System.Windows.RoutedEventArgs e)
public override void ActivateItem(IPlatformRoutedEventArgs e)
{
e.Handled = BaseTypesEntryNode.ActivateItem(this, type);
}
Expand Down
3 changes: 2 additions & 1 deletion ILSpy/TreeNodes/ILSpyTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using ICSharpCode.ILSpy.Options;
using ICSharpCode.ILSpyX.Abstractions;
using ICSharpCode.TreeView;
using ICSharpCode.TreeView.PlatformAbstractions;

namespace ICSharpCode.ILSpy.TreeNodes
{
Expand Down Expand Up @@ -77,7 +78,7 @@ public virtual bool View(ViewModels.TabPageModel tabPage)
return false;
}

public override void ActivateItemSecondary(RoutedEventArgs e)
public override void ActivateItemSecondary(IPlatformRoutedEventArgs e)
{
MainWindow.Instance.SelectNode(this, inNewTabPage: true);
MainWindow.Instance.Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)MainWindow.Instance.RefreshDecompiledView);
Expand Down
3 changes: 2 additions & 1 deletion ILSpy/TreeNodes/ModuleReferenceTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.TreeView.PlatformAbstractions;

namespace ICSharpCode.ILSpy.TreeNodes
{
Expand Down Expand Up @@ -69,7 +70,7 @@ public override object Text {

public override object Icon => Images.Library;

public override void ActivateItem(System.Windows.RoutedEventArgs e)
public override void ActivateItem(IPlatformRoutedEventArgs e)
{
var assemblyListNode = parentAssembly.Parent as AssemblyListTreeNode;
if (assemblyListNode != null && containsMetadata)
Expand Down
10 changes: 10 additions & 0 deletions SharpTreeView/PlatformAbstractions/IPlatformDataObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ICSharpCode.TreeView.PlatformAbstractions
{
public interface IPlatformDataObject
{
bool GetDataPresent(string format);
object GetData(string format);

void SetData(string format, object data);
}
}
7 changes: 7 additions & 0 deletions SharpTreeView/PlatformAbstractions/IPlatformDragDrop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ICSharpCode.TreeView.PlatformAbstractions
{
public interface IPlatformDragDrop
{
XPlatDragDropEffects DoDragDrop(object dragSource, object data, XPlatDragDropEffects allowedEffects);
}
}
8 changes: 8 additions & 0 deletions SharpTreeView/PlatformAbstractions/IPlatformDragEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ICSharpCode.TreeView.PlatformAbstractions
{
public interface IPlatformDragEventArgs
{
XPlatDragDropEffects Effects { get; set; }
IPlatformDataObject Data { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ICSharpCode.TreeView.PlatformAbstractions
{
public interface IPlatformRoutedEventArgs
{
bool Handled { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Windows;

namespace ICSharpCode.TreeView.PlatformAbstractions.WpfWindows
{
public class WpfWindowsDataObject : IPlatformDataObject
{
private readonly IDataObject _dataObject;

public WpfWindowsDataObject(IDataObject dataObject)
{
_dataObject = dataObject;
}

public object GetData(string format)
{
return _dataObject.GetData(format);
}

public bool GetDataPresent(string format)
{
return _dataObject.GetDataPresent(format);
}

public void SetData(string format, object data)
{
_dataObject.SetData(format, data);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Windows;

namespace ICSharpCode.TreeView.PlatformAbstractions.WpfWindows
{
public class WpfWindowsDragDropManager : IPlatformDragDrop
{
public XPlatDragDropEffects DoDragDrop(object dragSource, object data, XPlatDragDropEffects allowedEffects)
{
return (XPlatDragDropEffects)DragDrop.DoDragDrop(dragSource as DependencyObject, data, (DragDropEffects)allowedEffects);
}
}
}
Loading

0 comments on commit 4bd46c4

Please sign in to comment.