From 7446b6bc9ba3e6bd53da4285757a031ad9fb6b0b Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Thu, 7 Aug 2008 19:57:20 +0000 Subject: [PATCH] Improved documentation in several places; renamed 'Support' class in Nuclex.Support.Plugins to 'PluginHelper' to match the established conventions; provided better error messages for the plugin loading methods in the PluginRepository class git-svn-id: file:///srv/devel/repo-conversion/nusu@88 d2e56fa2-650e-0410-a79f-9358c0239efd --- Source/Licensing/LicenseKey.cs | 4 ++-- Source/Plugins/Employer.cs | 2 +- Source/Plugins/FactoryEmployer.cs | 2 +- Source/Plugins/InstanceEmployer.cs | 2 +- Source/Plugins/PluginHelper.cs | 4 ++-- Source/Plugins/PluginHost.cs | 12 ++++++++---- Source/Plugins/PluginRepository.cs | 21 ++++++++++++--------- Source/StringSegment.cs | 6 ++++-- 8 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Source/Licensing/LicenseKey.cs b/Source/Licensing/LicenseKey.cs index df8ce7e..555ce92 100644 --- a/Source/Licensing/LicenseKey.cs +++ b/Source/Licensing/LicenseKey.cs @@ -36,8 +36,8 @@ namespace Nuclex.Support.Licensing { /// /// Available storage space is used efficiently and allows for up to four /// 32 bit integers to be stored within the key, that's enough for a full GUID. - /// The four integers can be modified directly, for example to - /// store feature lists, checksums or other data within the key. + /// The four integers can be modified directly, for example to store feature + /// lists, checksums or other data within the key. /// /// public class LicenseKey { diff --git a/Source/Plugins/Employer.cs b/Source/Plugins/Employer.cs index 37b5207..43988b6 100644 --- a/Source/Plugins/Employer.cs +++ b/Source/Plugins/Employer.cs @@ -36,7 +36,7 @@ namespace Nuclex.Support.Plugins { /// Type which will be assessed /// True if the type can be employed public virtual bool CanEmploy(Type type) { - return Support.HasDefaultConstructor(type); + return PluginHelper.HasDefaultConstructor(type); } /// Employs the specified plugin type diff --git a/Source/Plugins/FactoryEmployer.cs b/Source/Plugins/FactoryEmployer.cs index 858bffb..d4425de 100644 --- a/Source/Plugins/FactoryEmployer.cs +++ b/Source/Plugins/FactoryEmployer.cs @@ -98,7 +98,7 @@ namespace Nuclex.Support.Plugins { /// True if the type can be employed public override bool CanEmploy(Type type) { return - Support.HasDefaultConstructor(type) && + PluginHelper.HasDefaultConstructor(type) && typeof(T).IsAssignableFrom(type); } diff --git a/Source/Plugins/InstanceEmployer.cs b/Source/Plugins/InstanceEmployer.cs index b9c2d51..aff347f 100644 --- a/Source/Plugins/InstanceEmployer.cs +++ b/Source/Plugins/InstanceEmployer.cs @@ -61,7 +61,7 @@ namespace Nuclex.Support.Plugins { /// True if the type can be employed public override bool CanEmploy(Type type) { return - Support.HasDefaultConstructor(type) && + PluginHelper.HasDefaultConstructor(type) && typeof(T).IsAssignableFrom(type); } diff --git a/Source/Plugins/PluginHelper.cs b/Source/Plugins/PluginHelper.cs index 0417dba..d13f538 100644 --- a/Source/Plugins/PluginHelper.cs +++ b/Source/Plugins/PluginHelper.cs @@ -22,8 +22,8 @@ using System; namespace Nuclex.Support.Plugins { - /// Supporting functions for the assembly - internal static class Support { + /// Supporting functions for the plugin classes + internal static class PluginHelper { /// Determines whether the given type has a default constructor /// Type which is to be checked diff --git a/Source/Plugins/PluginHost.cs b/Source/Plugins/PluginHost.cs index 7a824f2..e45e660 100644 --- a/Source/Plugins/PluginHost.cs +++ b/Source/Plugins/PluginHost.cs @@ -77,19 +77,23 @@ namespace Nuclex.Support.Plugins { foreach(Type type in assembly.GetTypes()) { // We'll ignore abstract and non-public types - if(!type.IsPublic || type.IsAbstract) + if(!type.IsPublic || type.IsAbstract) { continue; + } // Types that have been tagged with the [NoPlugin] attribute will be ignored object[] attributes = type.GetCustomAttributes(true); - foreach(object attribute in attributes) - if(attribute is NoPluginAttribute) + for(int index = 0; index < attributes.Length; ++index) { + if(attributes[index] is NoPluginAttribute) { continue; + } + } // Type seems to be acceptable, assess and possibly employ it try { - if(this.employer.CanEmploy(type)) + if(this.employer.CanEmploy(type)) { this.employer.Employ(type); + } } catch(Exception exception) { System.Console.WriteLine( diff --git a/Source/Plugins/PluginRepository.cs b/Source/Plugins/PluginRepository.cs index 25bb2f3..b5fca8b 100644 --- a/Source/Plugins/PluginRepository.cs +++ b/Source/Plugins/PluginRepository.cs @@ -65,28 +65,30 @@ namespace Nuclex.Support.Plugins { // File not found - Most likely a missing dependency of the assembly we // attempted to load since the assembly itself has been found by the GetFiles() method catch(DllNotFoundException exception) { - System.Console.WriteLine( - "Assembly not found, missing dependencies? " + exception.Message + Console.WriteLine( + "Assembly '" + assemblyFile + "' or one of its dependencies is missing" ); } // Unauthorized acccess - Either the assembly is not trusted because it contains // code that imposes a security risk on the system or a user rights problem catch(UnauthorizedAccessException exception) { - System.Console.WriteLine( - "Not authorized, user rights problem? " + exception.Message + Console.WriteLine( + "Not authorized to load assembly '" + assemblyFile + "', " + + "possible rights problem" ); } // Bad image format - This exception is often thrown when the assembly we // attempted to load requires a different version of the .NET framework catch(BadImageFormatException exception) { - System.Console.WriteLine( - "Not a .NET assembly or wrong runtime version. " + exception.Message + Console.WriteLine( + "'" + assemblyFile +"' is not a .NET assembly, requires a different version " + + "of the .NET Runtime or does not support the current instruction set (x86/x64)" ); } // Unknown error - Our last resort is to show a default error message catch(Exception exception) { - System.Console.WriteLine( - "Failed to load plugin. " + exception.Message + Console.WriteLine( + "Failed to load plugin assembly '" + assemblyFile + "': " + exception.Message ); } @@ -102,8 +104,9 @@ namespace Nuclex.Support.Plugins { this.assemblies.Add(assembly); // Trigger event in case any subscribers have been registered - if(AssemblyLoaded != null) + if(AssemblyLoaded != null) { AssemblyLoaded(this, new AssemblyLoadEventArgs(assembly)); + } } /// List of all loaded plugin assemblies in the repository diff --git a/Source/StringSegment.cs b/Source/StringSegment.cs index 919bc08..f425c4a 100644 --- a/Source/StringSegment.cs +++ b/Source/StringSegment.cs @@ -120,7 +120,7 @@ namespace Nuclex.Support { /// Returns the hash code for the current instance /// A 32-bit signed integer hash code public override int GetHashCode() { - return ((this.text.GetHashCode() ^ this.offset) ^ this.count); + return this.text.GetHashCode() ^ this.offset ^ this.count; } /// @@ -132,7 +132,9 @@ namespace Nuclex.Support { /// /// The object to be compared with the current instance public override bool Equals(object other) { - return ((other is StringSegment) && this.Equals((StringSegment)other)); + return + (other is StringSegment) && + this.Equals((StringSegment)other); } ///