Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF Refactoring #3274

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ICSharpCode.ILSpyX/AssemblyList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public string ListName {
get { return listName; }
}

internal void Move(LoadedAssembly[] assembliesToMove, int index)
public void Move(LoadedAssembly[] assembliesToMove, int index)
{
VerifyAccess();
lock (lockObj)
Expand Down Expand Up @@ -230,7 +230,7 @@ static bool CollectionChangeHasEffectOnSave(NotifyCollectionChangedEventArgs e)
}
}

internal void RefreshSave()
public void RefreshSave()
{
// Whenever the assembly list is modified, mark it as dirty
// and enqueue a task that saves it once the UI has finished modifying the assembly list.
Expand Down Expand Up @@ -281,8 +281,9 @@ public LoadedAssembly OpenAssembly(string file, bool isAutoLoaded = false)
{
file = Path.GetFullPath(file);
return OpenAssembly(file, () => {
var newAsm = new LoadedAssembly(this, file, fileLoaders: manager?.LoaderRegistry, applyWinRTProjections: ApplyWinRTProjections, useDebugSymbols: UseDebugSymbols);
newAsm.IsAutoLoaded = isAutoLoaded;
var newAsm = new LoadedAssembly(this, file, fileLoaders: manager?.LoaderRegistry, applyWinRTProjections: ApplyWinRTProjections, useDebugSymbols: UseDebugSymbols) {
IsAutoLoaded = isAutoLoaded
};
return newAsm;
});
}
Expand Down
9 changes: 4 additions & 5 deletions ICSharpCode.ILSpyX/AssemblyListManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public sealed class AssemblyListManager
public const string DotNet35List = ".NET 3.5";
public const string ASPDotNetMVC3List = "ASP.NET (MVC3)";

private ISettingsProvider settingsProvider;
private readonly ISettingsProvider settingsProvider;

public AssemblyListManager(ISettingsProvider settingsProvider)
{
Expand All @@ -59,24 +59,23 @@ public AssemblyListManager(ISettingsProvider settingsProvider)

public bool UseDebugSymbols { get; set; }

public ObservableCollection<string> AssemblyLists { get; } = new ObservableCollection<string>();
public ObservableCollection<string> AssemblyLists { get; } = [];

public FileLoaderRegistry LoaderRegistry { get; } = new FileLoaderRegistry();
public FileLoaderRegistry LoaderRegistry { get; } = new();

/// <summary>
/// Loads an assembly list from the ILSpySettings.
/// If no list with the specified name is found, the default list is loaded instead.
/// </summary>
public AssemblyList LoadList(string listName)
{
this.settingsProvider = this.settingsProvider.Load();
AssemblyList list = DoLoadList(listName);
if (!AssemblyLists.Contains(list.ListName))
AssemblyLists.Add(list.ListName);
return list;
}

AssemblyList DoLoadList(string listName)
AssemblyList DoLoadList(string? listName)
{
XElement doc = this.settingsProvider["AssemblyLists"];
if (listName != null)
Expand Down
2 changes: 1 addition & 1 deletion ICSharpCode.ILSpyX/Extensions/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace ICSharpCode.ILSpyX.Extensions
{
public static class CollectionExtensions
{
public static void AddRange<T>(this ICollection<T> list, IEnumerable<T> items)
internal static void AddRange<T>(this ICollection<T> list, IEnumerable<T> items)
{
foreach (T item in items)
if (!list.Contains(item))
Expand Down
1 change: 0 additions & 1 deletion ICSharpCode.ILSpyX/ICSharpCode.ILSpyX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="ILSpy" Key="00240000048000009400000006020000002400005253413100040000010001004dcf3979c4e902efa4dd2163a039701ed5822e6f1134d77737296abbb97bf0803083cfb2117b4f5446a217782f5c7c634f9fe1fc60b4c11d62c5b3d33545036706296d31903ddcf750875db38a8ac379512f51620bb948c94d0831125fbc5fe63707cbb93f48c1459c4d1749eb7ac5e681a2f0d6d7c60fa527a3c0b8f92b02bf" />
<InternalsVisibleTo Include="ILSpy.Tests" Key="00240000048000009400000006020000002400005253413100040000010001004dcf3979c4e902efa4dd2163a039701ed5822e6f1134d77737296abbb97bf0803083cfb2117b4f5446a217782f5c7c634f9fe1fc60b4c11d62c5b3d33545036706296d31903ddcf750875db38a8ac379512f51620bb948c94d0831125fbc5fe63707cbb93f48c1459c4d1749eb7ac5e681a2f0d6d7c60fa527a3c0b8f92b02bf" />
</ItemGroup>

Expand Down
8 changes: 4 additions & 4 deletions ICSharpCode.ILSpyX/LoadedPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public enum PackageKind

public PackageKind Kind { get; }

internal SingleFileBundle.Header BundleHeader { get; set; }
public SingleFileBundle.Header BundleHeader { get; set; }

/// <summary>
/// List of all entries, including those in sub-directories within the package.
/// </summary>
public IReadOnlyList<PackageEntry> Entries { get; }

internal PackageFolder RootFolder { get; }
public PackageFolder RootFolder { get; }

public LoadedPackage(PackageKind kind, IEnumerable<PackageEntry> entries)
{
Expand Down Expand Up @@ -256,7 +256,7 @@ public abstract class PackageEntry : Resource
public abstract string FullName { get; }
}

sealed class PackageFolder : IAssemblyResolver
public sealed class PackageFolder : IAssemblyResolver
{
/// <summary>
/// Gets the short name of the folder.
Expand Down Expand Up @@ -326,7 +326,7 @@ internal PackageFolder(LoadedPackage package, PackageFolder? parent, string name

readonly Dictionary<string, LoadedAssembly?> assemblies = new Dictionary<string, LoadedAssembly?>(StringComparer.OrdinalIgnoreCase);

internal LoadedAssembly? ResolveFileName(string name)
public LoadedAssembly? ResolveFileName(string name)
{
if (package.LoadedAssembly == null)
return null;
Expand Down
6 changes: 3 additions & 3 deletions ICSharpCode.ILSpyX/PdbProvider/PortableDebugInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@

namespace ICSharpCode.ILSpyX.PdbProvider
{
class PortableDebugInfoProvider : IDebugInfoProvider
public class PortableDebugInfoProvider : IDebugInfoProvider
{
string? pdbFileName;
string moduleFileName;
readonly MetadataReaderProvider provider;
MetadataReaderOptions options;
bool hasError;

internal bool IsEmbedded => pdbFileName == null;
public bool IsEmbedded => pdbFileName == null;

public PortableDebugInfoProvider(string moduleFileName, MetadataReaderProvider provider,
MetadataReaderOptions options = MetadataReaderOptions.Default,
Expand Down Expand Up @@ -69,7 +69,7 @@ public string Description {
}
}

internal MetadataReader? GetMetadataReader()
public MetadataReader? GetMetadataReader()
{
try
{
Expand Down
72 changes: 25 additions & 47 deletions ICSharpCode.ILSpyX/Settings/ILSpySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,11 @@ public class ILSpySettings : ISettingsProvider
/// </summary>
public static ISettingsFilePathProvider? SettingsFilePathProvider { get; set; }

readonly XElement root;
XElement root;

ILSpySettings()
ILSpySettings(XElement? root = null)
{
this.root = new XElement("ILSpy");
}

ILSpySettings(XElement root)
{
this.root = root;
this.root = root ?? new XElement("ILSpy");
}

public XElement this[XName section] {
Expand All @@ -64,13 +59,7 @@ public static ILSpySettings Load()
{
try
{
XDocument doc = LoadWithoutCheckingCharacters(GetConfigFile());
if (null == doc.Root)
{
return new ILSpySettings();
}

return new ILSpySettings(doc.Root);
return new ILSpySettings(LoadFile(GetConfigFile()).Root);
}
catch (IOException)
{
Expand All @@ -83,40 +72,39 @@ public static ILSpySettings Load()
}
}

static XDocument LoadWithoutCheckingCharacters(string fileName)
static XDocument LoadFile(string fileName)
{
return XDocument.Load(fileName, LoadOptions.None);
}

/// <summary>
/// Saves a setting section.
/// </summary>
public static void SaveSettings(XElement section)
public void SaveSettings(XElement section)
{
Update(
delegate (XElement root) {
XElement? existingElement = root.Element(section.Name);
if (existingElement != null)
existingElement.ReplaceWith(section);
else
root.Add(section);
});
Update(rootElement => {
XElement? existingElement = rootElement.Element(section.Name);
if (existingElement != null)
existingElement.ReplaceWith(section);
else
rootElement.Add(section);
});
}

/// <summary>
/// Updates the saved settings.
/// We always reload the file on updates to ensure we aren't overwriting unrelated changes performed
/// by another ILSpy instance.
/// </summary>
public static void Update(Action<XElement> action)
public void Update(Action<XElement> action)
{
using (new MutexProtector(ConfigFileMutex))
{
string config = GetConfigFile();
XDocument doc;
try
{
doc = LoadWithoutCheckingCharacters(config);
doc = LoadFile(config);
}
catch (IOException)
{
Expand All @@ -131,14 +119,10 @@ public static void Update(Action<XElement> action)
doc.Root!.SetAttributeValue("version", DecompilerVersionInfo.Major + "." + DecompilerVersionInfo.Minor + "." + DecompilerVersionInfo.Build + "." + DecompilerVersionInfo.Revision);
action(doc.Root);
doc.Save(config, SaveOptions.None);
this.root = doc.Root;
}
}

void ISettingsProvider.Update(Action<XElement> action)
{
Update(action);
}

static string GetConfigFile()
{
if (null != SettingsFilePathProvider)
Expand All @@ -148,11 +132,6 @@ static string GetConfigFile()
// return "ILSpy.xml";
}

ISettingsProvider ISettingsProvider.Load()
{
return Load();
}

const string ConfigFileMutex = "01A91708-49D1-410D-B8EB-4DE2662B3971";

/// <summary>
Expand All @@ -164,17 +143,16 @@ sealed class MutexProtector : IDisposable

public MutexProtector(string name)
{
bool createdNew;
this.mutex = new Mutex(true, name, out createdNew);
if (!createdNew)
this.mutex = new Mutex(true, name, out bool createdNew);
if (createdNew)
return;

try
{
mutex.WaitOne();
}
catch (AbandonedMutexException)
{
try
{
mutex.WaitOne();
}
catch (AbandonedMutexException)
{
}
}
}

Expand Down
42 changes: 0 additions & 42 deletions ICSharpCode.ILSpyX/Settings/IMiscSettings.cs

This file was deleted.

2 changes: 0 additions & 2 deletions ICSharpCode.ILSpyX/Settings/ISettingsFilePathProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

using System;

namespace ICSharpCode.ILSpyX.Settings
{
public interface ISettingsFilePathProvider
Expand Down
39 changes: 1 addition & 38 deletions ICSharpCode.ILSpyX/Settings/ISettingsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,16 @@
// DEALINGS IN THE SOFTWARE.

using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;

using static System.Collections.Specialized.BitVector32;

namespace ICSharpCode.ILSpyX.Settings
{
public interface ISettingsProvider
{
XElement this[XName section] { get; }

void Update(Action<XElement> action);
ISettingsProvider Load();

public static ICSharpCode.Decompiler.DecompilerSettings LoadDecompilerSettings(ISettingsProvider settingsProvider)
{
XElement e = settingsProvider["DecompilerSettings"];
var newSettings = new Decompiler.DecompilerSettings();
var properties = typeof(Decompiler.DecompilerSettings).GetProperties()
.Where(p => p.GetCustomAttribute<BrowsableAttribute>()?.Browsable != false);
foreach (var p in properties)
{
var value = (bool?)e.Attribute(p.Name);
if (value.HasValue)
p.SetValue(newSettings, value.Value);
}
return newSettings;
}

public static void SaveDecompilerSettings(XElement root, ICSharpCode.Decompiler.DecompilerSettings newSettings)
{
var properties = typeof(Decompiler.DecompilerSettings).GetProperties()
.Where(p => p.GetCustomAttribute<BrowsableAttribute>()?.Browsable != false);

XElement section = new XElement("DecompilerSettings");
foreach (var p in properties)
{
section.SetAttributeValue(p.Name, p.GetValue(newSettings));
}

XElement? existingElement = root.Element("DecompilerSettings");
if (existingElement != null)
existingElement.ReplaceWith(section);
else
root.Add(section);
}
void SaveSettings(XElement section);
}
}
Loading
Loading