Browse Source

Add plugin support using MEF.

pull/70/head
Daniel Grunwald 15 years ago
parent
commit
c23e29e75c
  1. 8
      ILSpy/App.xaml.cs
  2. 3
      ILSpy/CSharpLanguage.cs
  3. 2
      ILSpy/GacInterop.cs
  4. 4
      ILSpy/GuessFileType.cs
  5. 3
      ILSpy/ILSpy.csproj
  6. 25
      ILSpy/Language.cs
  7. 2
      ILSpy/NavigationHistory.cs

8
ILSpy/App.xaml.cs

@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.ComponentModel.Composition.Hosting;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
@ -35,6 +36,13 @@ namespace ICSharpCode.ILSpy
{ {
InitializeComponent(); InitializeComponent();
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly));
catalog.Catalogs.Add(new DirectoryCatalog(".", "*.Plugin.dll"));
var container = new CompositionContainer(catalog);
Languages.Initialize(container);
if (!Debugger.IsAttached) { if (!Debugger.IsAttached) {
AppDomain.CurrentDomain.UnhandledException += ShowErrorBox; AppDomain.CurrentDomain.UnhandledException += ShowErrorBox;
Dispatcher.CurrentDispatcher.UnhandledException += Dispatcher_UnhandledException; Dispatcher.CurrentDispatcher.UnhandledException += Dispatcher_UnhandledException;

3
ILSpy/CSharpLanguage.cs

@ -19,13 +19,13 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Resources; using System.Resources;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xaml; using System.Xaml;
using System.Xml; using System.Xml;
using ICSharpCode.Decompiler; using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.Ast; using ICSharpCode.Decompiler.Ast;
using ICSharpCode.Decompiler.Ast.Transforms; using ICSharpCode.Decompiler.Ast.Transforms;
@ -37,6 +37,7 @@ namespace ICSharpCode.ILSpy
/// <summary> /// <summary>
/// Decompiler logic for C#. /// Decompiler logic for C#.
/// </summary> /// </summary>
[Export(typeof(Language))]
public class CSharpLanguage : Language public class CSharpLanguage : Language
{ {
string name = "C#"; string name = "C#";

2
ILSpy/GacInterop.cs

@ -28,7 +28,7 @@ namespace ICSharpCode.ILSpy
/// <summary> /// <summary>
/// Interop with the .NET GAC. /// Interop with the .NET GAC.
/// </summary> /// </summary>
public static class GacInterop static class GacInterop
{ {
/// <summary> /// <summary>
/// Gets the names of all assemblies in the GAC. /// Gets the names of all assemblies in the GAC.

4
ILSpy/GuessFileType.cs

@ -12,7 +12,7 @@ namespace ICSharpCode.ILSpy
/// <summary> /// <summary>
/// Static methods for determining the type of a file. /// Static methods for determining the type of a file.
/// </summary> /// </summary>
public static class GuessFileType static class GuessFileType
{ {
public static FileType DetectFileType(Stream stream) public static FileType DetectFileType(Stream stream)
{ {
@ -120,7 +120,7 @@ namespace ICSharpCode.ILSpy
} }
} }
public enum FileType enum FileType
{ {
Binary, Binary,
Text, Text,

3
ILSpy/ILSpy.csproj

@ -55,6 +55,9 @@
<RequiredTargetFramework>3.0</RequiredTargetFramework> <RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel.Composition">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Core"> <Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework> <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference> </Reference>

25
ILSpy/Language.cs

@ -19,6 +19,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel.Composition.Hosting;
using System.Linq; using System.Linq;
using ICSharpCode.Decompiler; using ICSharpCode.Decompiler;
using Mono.Cecil; using Mono.Cecil;
@ -121,19 +122,29 @@ namespace ICSharpCode.ILSpy
public static class Languages public static class Languages
{ {
static ReadOnlyCollection<Language> allLanguages;
/// <summary> /// <summary>
/// A list of all languages. /// A list of all languages.
/// </summary> /// </summary>
public static readonly ReadOnlyCollection<Language> AllLanguages = new List<Language>( public static ReadOnlyCollection<Language> AllLanguages {
new Language[] { get {
new CSharpLanguage(), return allLanguages;
new ILLanguage(true)
} }
}
internal static void Initialize(CompositionContainer composition)
{
List<Language> languages = new List<Language>();
languages.AddRange(composition.GetExportedValues<Language>());
languages.Add(new ILLanguage(true));
#if DEBUG #if DEBUG
.Concat(ILAstLanguage.GetDebugLanguages()) languages.AddRange(ILAstLanguage.GetDebugLanguages());
.Concat(CSharpLanguage.GetDebugLanguages()) languages.AddRange(CSharpLanguage.GetDebugLanguages());
#endif #endif
).AsReadOnly(); allLanguages = languages.AsReadOnly();
}
/// <summary> /// <summary>
/// Gets a language using its name. /// Gets a language using its name.

2
ILSpy/NavigationHistory.cs

@ -10,7 +10,7 @@ namespace ICSharpCode.ILSpy
/// <summary> /// <summary>
/// Stores the navigation history. /// Stores the navigation history.
/// </summary> /// </summary>
public class NavigationHistory sealed class NavigationHistory
{ {
List<SharpTreeNode> back = new List<SharpTreeNode>(); List<SharpTreeNode> back = new List<SharpTreeNode>();
List<SharpTreeNode> forward = new List<SharpTreeNode>(); List<SharpTreeNode> forward = new List<SharpTreeNode>();

Loading…
Cancel
Save