From cc652816f1b6261827c2adaee49c03df1ae77e65 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 22 Jun 2013 19:54:36 +0200 Subject: [PATCH] Use AssemblyLoader.Create() in demo app. --- .../Refactoring/Script.cs | 2 +- ICSharpCode.NRefactory.Cecil/CecilLoader.cs | 31 +---- .../ICSharpCode.NRefactory.Cecil.csproj | 105 ++++++++--------- .../Properties/AssemblyInfo.cs | 24 +--- .../Program.cs | 2 +- .../Solution.cs | 2 +- ICSharpCode.NRefactory.Demo/CSDemo.cs | 2 +- ICSharpCode.NRefactory.GtkDemo/MainWindow.cs | 2 +- .../ICSharpCode.NRefactory.IKVM.csproj | 107 +++++++++--------- ICSharpCode.NRefactory.IKVM/IkvmLoader.cs | 33 +----- .../Properties/AssemblyInfo.cs | 25 +--- ICSharpCode.NRefactory/IAnnotatable.cs | 2 +- .../Properties/GlobalAssemblyInfo.cs | 2 +- .../TypeSystem/AssemblyLoader.cs | 54 +++++++-- 14 files changed, 172 insertions(+), 221 deletions(-) diff --git a/ICSharpCode.NRefactory.CSharp/Refactoring/Script.cs b/ICSharpCode.NRefactory.CSharp/Refactoring/Script.cs index a998f6ad0..8218804f4 100644 --- a/ICSharpCode.NRefactory.CSharp/Refactoring/Script.cs +++ b/ICSharpCode.NRefactory.CSharp/Refactoring/Script.cs @@ -216,7 +216,7 @@ public void ChangeModifier(EntityDeclaration entity, Modifiers modifiers) /// Adds an attribute section to a given entity. /// /// The entity to add the attribute to. - /// The attribute to add. + /// The attribute to add. public void AddAttribute(EntityDeclaration entity, AttributeSection attr) { var node = entity.FirstChild; diff --git a/ICSharpCode.NRefactory.Cecil/CecilLoader.cs b/ICSharpCode.NRefactory.Cecil/CecilLoader.cs index ee394c145..6fe1cc230 100644 --- a/ICSharpCode.NRefactory.Cecil/CecilLoader.cs +++ b/ICSharpCode.NRefactory.Cecil/CecilLoader.cs @@ -47,10 +47,7 @@ public sealed class CecilLoader : AssemblyLoader const int cecilLoaderVersion = 1; #region Options - /// - /// Specifies whether to include internal members. The default is false. - /// - public bool IncludeInternalMembers { get; set; } + // Most options are defined in the AssemblyLoader base class /// /// Specifies whether to use lazy loading. The default is false. @@ -68,30 +65,6 @@ public sealed class CecilLoader : AssemblyLoader /// public bool LazyLoad { get; set; } - /// - /// Gets/Sets the documentation provider that is used to retrieve the XML documentation for all members. - /// - public IDocumentationProvider DocumentationProvider { get; set; } - - InterningProvider interningProvider; - - /// - /// Gets/Sets the interning provider. - /// - public InterningProvider InterningProvider { - get { return interningProvider; } - set { - if (value == null) - throw new ArgumentNullException(); - interningProvider = value; - } - } - - /// - /// Gets/Sets the cancellation token used by the cecil loader. - /// - public CancellationToken CancellationToken { get; set; } - /// /// This delegate gets executed whenever an entity was loaded. /// @@ -120,8 +93,6 @@ public InterningProvider InterningProvider { /// public CecilLoader() { - // Enable interning by default. - this.InterningProvider = new SimpleInterningProvider(); } /// diff --git a/ICSharpCode.NRefactory.Cecil/ICSharpCode.NRefactory.Cecil.csproj b/ICSharpCode.NRefactory.Cecil/ICSharpCode.NRefactory.Cecil.csproj index c14dd05be..dff9914f6 100644 --- a/ICSharpCode.NRefactory.Cecil/ICSharpCode.NRefactory.Cecil.csproj +++ b/ICSharpCode.NRefactory.Cecil/ICSharpCode.NRefactory.Cecil.csproj @@ -1,52 +1,55 @@ - - - - Debug - AnyCPU - 10.0.0 - 2.0 - {2B8F4F83-C2B3-4E84-A27B-8DEE1BE0E006} - Library - ICSharpCode.NRefactory.Cecil - ICSharpCode.NRefactory.Cecil - true - ..\ICSharpCode.NRefactory.snk - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - false - - - full - true - bin\Release - prompt - 4 - false - - - - - - - - - - - - - {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} - ICSharpCode.NRefactory - - - {D68133BD-1E63-496E-9EDE-4FBDBF77B486} - Mono.Cecil - - + + + + Debug + AnyCPU + 10.0.0 + 2.0 + {2B8F4F83-C2B3-4E84-A27B-8DEE1BE0E006} + Library + ICSharpCode.NRefactory.Cecil + ICSharpCode.NRefactory.Cecil + true + ..\ICSharpCode.NRefactory.snk + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + full + true + bin\Release + prompt + 4 + false + + + + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + + {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} + ICSharpCode.NRefactory + + + {D68133BD-1E63-496E-9EDE-4FBDBF77B486} + Mono.Cecil + + \ No newline at end of file diff --git a/ICSharpCode.NRefactory.Cecil/Properties/AssemblyInfo.cs b/ICSharpCode.NRefactory.Cecil/Properties/AssemblyInfo.cs index 7023d0399..ccb27b40b 100644 --- a/ICSharpCode.NRefactory.Cecil/Properties/AssemblyInfo.cs +++ b/ICSharpCode.NRefactory.Cecil/Properties/AssemblyInfo.cs @@ -23,30 +23,14 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. + +using System; using System.Reflection; -using System.Runtime.CompilerServices; // Information about this assembly is defined by the following attributes. // Change them to the values specific to your project. [assembly: AssemblyTitle("ICSharpCode.NRefactory.Cecil")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("Xamarin Inc. (http://xamarin.com)")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("1.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] +[assembly: AssemblyDescription("Cecil Assembly Loader for NRefactory")] +[assembly: CLSCompliant(true)] diff --git a/ICSharpCode.NRefactory.ConsistencyCheck/Program.cs b/ICSharpCode.NRefactory.ConsistencyCheck/Program.cs index 0cce00b00..578a144d5 100644 --- a/ICSharpCode.NRefactory.ConsistencyCheck/Program.cs +++ b/ICSharpCode.NRefactory.ConsistencyCheck/Program.cs @@ -85,7 +85,7 @@ static void RunTestOnAllFiles(string title, Action runTest) public static IUnresolvedAssembly LoadAssembly(string assemblyFileName) { - return assemblyDict.GetOrAdd(assemblyFileName, file => new CecilLoader().LoadAssemblyFile(file)); + return assemblyDict.GetOrAdd(assemblyFileName, file => AssemblyLoader.Create().LoadAssemblyFile(file)); } } diff --git a/ICSharpCode.NRefactory.ConsistencyCheck/Solution.cs b/ICSharpCode.NRefactory.ConsistencyCheck/Solution.cs index 633a69669..ef249dd60 100644 --- a/ICSharpCode.NRefactory.ConsistencyCheck/Solution.cs +++ b/ICSharpCode.NRefactory.ConsistencyCheck/Solution.cs @@ -82,7 +82,7 @@ public Solution(string fileName) /// public IUnresolvedAssembly LoadAssembly(string assemblyFileName) { - return assemblyDict.GetOrAdd(assemblyFileName, file => new CecilLoader().LoadAssemblyFile(file)); + return assemblyDict.GetOrAdd(assemblyFileName, file => AssemblyLoader.Create().LoadAssemblyFile(file)); } } } diff --git a/ICSharpCode.NRefactory.Demo/CSDemo.cs b/ICSharpCode.NRefactory.Demo/CSDemo.cs index 08f3d62bd..bf9fd95d2 100644 --- a/ICSharpCode.NRefactory.Demo/CSDemo.cs +++ b/ICSharpCode.NRefactory.Demo/CSDemo.cs @@ -195,7 +195,7 @@ void CSharpTreeViewAfterSelect(object sender, TreeViewEventArgs e) 0, assemblies.Length, delegate (int i) { Stopwatch w = Stopwatch.StartNew(); - CecilLoader loader = new CecilLoader(); + AssemblyLoader loader = AssemblyLoader.Create(); projectContents[i] = loader.LoadAssemblyFile(assemblies[i].Location); Debug.WriteLine(Path.GetFileName(assemblies[i].Location) + ": " + w.Elapsed); }); diff --git a/ICSharpCode.NRefactory.GtkDemo/MainWindow.cs b/ICSharpCode.NRefactory.GtkDemo/MainWindow.cs index 43ab54125..cef66eeee 100644 --- a/ICSharpCode.NRefactory.GtkDemo/MainWindow.cs +++ b/ICSharpCode.NRefactory.GtkDemo/MainWindow.cs @@ -253,7 +253,7 @@ void HandleClicked (object sender, EventArgs e) 0, assemblies.Length, delegate (int i) { Stopwatch w = Stopwatch.StartNew(); - CecilLoader loader = new CecilLoader(); + AssemblyLoader loader = AssemblyLoader.Create(); projectContents[i] = loader.LoadAssemblyFile(assemblies[i].Location); }); return projectContents; diff --git a/ICSharpCode.NRefactory.IKVM/ICSharpCode.NRefactory.IKVM.csproj b/ICSharpCode.NRefactory.IKVM/ICSharpCode.NRefactory.IKVM.csproj index 2e92f5aa2..10cef85af 100644 --- a/ICSharpCode.NRefactory.IKVM/ICSharpCode.NRefactory.IKVM.csproj +++ b/ICSharpCode.NRefactory.IKVM/ICSharpCode.NRefactory.IKVM.csproj @@ -1,53 +1,56 @@ - - - - Debug - AnyCPU - 10.0.0 - 2.0 - {A727169F-D94F-443F-B305-B057D7F3B420} - Library - ICSharpCode.NRefactory.IKVM - ICSharpCode.NRefactory.IKVM - true - ..\ICSharpCode.NRefactory.snk - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - false - - - full - true - bin\Release - prompt - 4 - false - - - - - - - - - - - {4CB170EF-DFE6-4A56-9E1B-A85449E827A7} - IKVM.Reflection - - - {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} - ICSharpCode.NRefactory - - - - - + + + + Debug + AnyCPU + 10.0.0 + 2.0 + {A727169F-D94F-443F-B305-B057D7F3B420} + Library + ICSharpCode.NRefactory.IKVM + ICSharpCode.NRefactory.IKVM + true + ..\ICSharpCode.NRefactory.snk + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + full + true + bin\Release + prompt + 4 + false + + + + + + + Properties\GlobalAssemblyInfo.cs + + + + + + + {4CB170EF-DFE6-4A56-9E1B-A85449E827A7} + IKVM.Reflection + + + {3B2A5653-EC97-4001-BB9B-D90F1AF2C371} + ICSharpCode.NRefactory + + + + + \ No newline at end of file diff --git a/ICSharpCode.NRefactory.IKVM/IkvmLoader.cs b/ICSharpCode.NRefactory.IKVM/IkvmLoader.cs index 6e21aabad..6c771a11d 100644 --- a/ICSharpCode.NRefactory.IKVM/IkvmLoader.cs +++ b/ICSharpCode.NRefactory.IKVM/IkvmLoader.cs @@ -57,35 +57,8 @@ public sealed class IkvmLoader : AssemblyLoader const int ikvmLoaderVersion = 1; #region Options - /// - /// Specifies whether to include internal members. The default is false. - /// - public bool IncludeInternalMembers { get; set; } - - /// - /// Gets/Sets the documentation provider that is used to retrieve the XML documentation for all members. - /// - public IDocumentationProvider DocumentationProvider { get; set; } - - InterningProvider interningProvider; - - /// - /// Gets/Sets the interning provider. - /// - public InterningProvider InterningProvider { - get { return interningProvider; } - set { - if (value == null) - throw new ArgumentNullException(); - interningProvider = value; - } - } - - /// - /// Gets/Sets the cancellation token used by the cecil loader. - /// - public CancellationToken CancellationToken { get; set; } - + // Most options are defined in the AssemblyLoader base class + /// /// This delegate gets executed whenever an entity was loaded. /// @@ -103,8 +76,6 @@ public InterningProvider InterningProvider { /// public IkvmLoader() { - // Enable interning by default. - this.InterningProvider = new SimpleInterningProvider(); } #region Load Assembly From Disk diff --git a/ICSharpCode.NRefactory.IKVM/Properties/AssemblyInfo.cs b/ICSharpCode.NRefactory.IKVM/Properties/AssemblyInfo.cs index db6dd8dff..f3919fc3a 100644 --- a/ICSharpCode.NRefactory.IKVM/Properties/AssemblyInfo.cs +++ b/ICSharpCode.NRefactory.IKVM/Properties/AssemblyInfo.cs @@ -23,30 +23,15 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. + + +using System; using System.Reflection; -using System.Runtime.CompilerServices; // Information about this assembly is defined by the following attributes. // Change them to the values specific to your project. [assembly: AssemblyTitle("ICSharpCode.NRefactory.IKVM")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("Xamarin Inc. (http://xamarin.com)")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("1.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] +[assembly: AssemblyDescription("IKVM.Reflection-based Assembly Loader for NRefactory")] +[assembly: CLSCompliant(true)] diff --git a/ICSharpCode.NRefactory/IAnnotatable.cs b/ICSharpCode.NRefactory/IAnnotatable.cs index dedc90135..ba6357c68 100644 --- a/ICSharpCode.NRefactory/IAnnotatable.cs +++ b/ICSharpCode.NRefactory/IAnnotatable.cs @@ -181,7 +181,7 @@ public virtual void RemoveAnnotations (Type type) AnnotationList list = oldAnnotations as AnnotationList; if (list != null) { lock (list) - list.RemoveAll (obj => type.IsInstanceOfType (obj)); + list.RemoveAll(type.IsInstanceOfType); } else if (type.IsInstanceOfType (oldAnnotations)) { if (Interlocked.CompareExchange (ref this.annotations, null, oldAnnotations) != oldAnnotations) { // Operation failed (some other thread wrote to this.annotations first) diff --git a/ICSharpCode.NRefactory/Properties/GlobalAssemblyInfo.cs b/ICSharpCode.NRefactory/Properties/GlobalAssemblyInfo.cs index e18bab610..7f62c0b91 100644 --- a/ICSharpCode.NRefactory/Properties/GlobalAssemblyInfo.cs +++ b/ICSharpCode.NRefactory/Properties/GlobalAssemblyInfo.cs @@ -29,7 +29,7 @@ // associated with an assembly. [assembly: AssemblyCompany("ICSharpCode")] [assembly: AssemblyProduct("SharpDevelop/MonoDevelop")] -[assembly: AssemblyCopyright("Copyright 2010-2013 AlphaSierraPapa")] +[assembly: AssemblyCopyright("Copyright 2010-2013 AlphaSierraPapa and Xamarin Inc.")] // This sets the default COM visibility of types in the assembly to invisible. // If you need to expose a type to COM, use [ComVisible(true)] on that type. diff --git a/ICSharpCode.NRefactory/TypeSystem/AssemblyLoader.cs b/ICSharpCode.NRefactory/TypeSystem/AssemblyLoader.cs index 4582843d4..567c5b02f 100644 --- a/ICSharpCode.NRefactory/TypeSystem/AssemblyLoader.cs +++ b/ICSharpCode.NRefactory/TypeSystem/AssemblyLoader.cs @@ -25,7 +25,10 @@ // THE SOFTWARE. using System; using System.Reflection; +using System.Threading; +using ICSharpCode.NRefactory.Documentation; using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.NRefactory.TypeSystem.Implementation; namespace ICSharpCode.NRefactory { @@ -37,24 +40,55 @@ public enum AssemblyLoaderBackend { public abstract class AssemblyLoader { + public static AssemblyLoader Create () + { + return Create (AssemblyLoaderBackend.Auto); + } + public static AssemblyLoader Create (AssemblyLoaderBackend backend) { switch (backend) { - case AssemblyLoaderBackend.Auto: - case AssemblyLoaderBackend.Cecil: - return (AssemblyLoader)Assembly.Load ("ICSharpCode.NRefactory.Cecil").CreateInstance ("ICSharpCode.NRefactory.TypeSystem.CecilLoader"); - case AssemblyLoaderBackend.IKVM: - return (AssemblyLoader)Assembly.Load ("ICSharpCode.NRefactory.IKVM").CreateInstance ("ICSharpCode.NRefactory.TypeSystem.IkvmLoader"); - default: - throw new ArgumentOutOfRangeException (); + case AssemblyLoaderBackend.Auto: + case AssemblyLoaderBackend.Cecil: + return (AssemblyLoader)Assembly.Load ("ICSharpCode.NRefactory.Cecil").CreateInstance ("ICSharpCode.NRefactory.TypeSystem.CecilLoader"); + case AssemblyLoaderBackend.IKVM: + return (AssemblyLoader)Assembly.Load ("ICSharpCode.NRefactory.IKVM").CreateInstance ("ICSharpCode.NRefactory.TypeSystem.IkvmLoader"); + default: + throw new ArgumentOutOfRangeException (); } } - public abstract IUnresolvedAssembly LoadAssemblyFile(string fileName); + /// + /// Specifies whether to include internal members. The default is false. + /// + public bool IncludeInternalMembers { get; set; } + + /// + /// Gets/Sets the cancellation token used by the assembly loader. + /// + public CancellationToken CancellationToken { get; set; } + + /// + /// Gets/Sets the documentation provider that is used to retrieve the XML documentation for all members. + /// + public IDocumentationProvider DocumentationProvider { get; set; } - internal AssemblyLoader () - { + [CLSCompliant(false)] + protected InterningProvider interningProvider = new SimpleInterningProvider(); + + /// + /// Gets/Sets the interning provider. + /// + public InterningProvider InterningProvider { + get { return interningProvider; } + set { + if (value == null) + throw new ArgumentNullException(); + interningProvider = value; + } } + + public abstract IUnresolvedAssembly LoadAssemblyFile(string fileName); } }