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
This commit is contained in:
Markus Ewald 2008-08-07 19:57:20 +00:00
parent b0026fcdd6
commit 7446b6bc9b
8 changed files with 31 additions and 22 deletions

View File

@ -36,8 +36,8 @@ namespace Nuclex.Support.Licensing {
/// <para>
/// 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.
/// </para>
/// </remarks>
public class LicenseKey {

View File

@ -36,7 +36,7 @@ namespace Nuclex.Support.Plugins {
/// <param name="type">Type which will be assessed</param>
/// <returns>True if the type can be employed</returns>
public virtual bool CanEmploy(Type type) {
return Support.HasDefaultConstructor(type);
return PluginHelper.HasDefaultConstructor(type);
}
/// <summary>Employs the specified plugin type</summary>

View File

@ -98,7 +98,7 @@ namespace Nuclex.Support.Plugins {
/// <returns>True if the type can be employed</returns>
public override bool CanEmploy(Type type) {
return
Support.HasDefaultConstructor(type) &&
PluginHelper.HasDefaultConstructor(type) &&
typeof(T).IsAssignableFrom(type);
}

View File

@ -61,7 +61,7 @@ namespace Nuclex.Support.Plugins {
/// <returns>True if the type can be employed</returns>
public override bool CanEmploy(Type type) {
return
Support.HasDefaultConstructor(type) &&
PluginHelper.HasDefaultConstructor(type) &&
typeof(T).IsAssignableFrom(type);
}

View File

@ -22,8 +22,8 @@ using System;
namespace Nuclex.Support.Plugins {
/// <summary>Supporting functions for the assembly</summary>
internal static class Support {
/// <summary>Supporting functions for the plugin classes</summary>
internal static class PluginHelper {
/// <summary>Determines whether the given type has a default constructor</summary>
/// <param name="type">Type which is to be checked</param>

View File

@ -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(

View File

@ -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));
}
}
/// <summary>List of all loaded plugin assemblies in the repository</summary>

View File

@ -120,7 +120,7 @@ namespace Nuclex.Support {
/// <summary>Returns the hash code for the current instance</summary>
/// <returns>A 32-bit signed integer hash code</returns>
public override int GetHashCode() {
return ((this.text.GetHashCode() ^ this.offset) ^ this.count);
return this.text.GetHashCode() ^ this.offset ^ this.count;
}
/// <summary>
@ -132,7 +132,9 @@ namespace Nuclex.Support {
/// </returns>
/// <param name="other">The object to be compared with the current instance</param>
public override bool Equals(object other) {
return ((other is StringSegment) && this.Equals((StringSegment)other));
return
(other is StringSegment) &&
this.Equals((StringSegment)other);
}
/// <summary>