- Alexey.
-------- Original Message --------
| Subject: | Re: There seems an easy fix for loading custom classes. What do you think? |
|---|---|
| Date: | Fri, 20 Feb 2004 10:33:34 -0800 |
| From: | Alexey N. Solofnenko <[EMAIL PROTECTED]> |
| Reply-To: | Log4NET User <[email protected]> |
| To: | Log4NET User <[email protected]> |
| References: | <[EMAIL PROTECTED]> |
Type type=relativeAssembly.GetType(typeName, false, ignoreCase);
if (type!=null) return type;
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) {
type=assembly.GetType(typeName, false, ignoreCase);
if (type!=null) return type;
}
if (throwOnError) throw new TypeLoadException("Type '"+typeName+"' cannot be found");
else return null;
- Alexey.
Alexey N. Solofnenko wrote:
Hello,
I have tried the following code in SystemInfo.getTypeFromString() and it works well on my computer. Instead of looking for a class in just relativeAssembly, all loaded assemblies are searched for the class. Do you think log4net can be updated to do the same?
Sincerely,
Alexey Solofnenko.
public static Type GetTypeFromString(Assembly relativeAssembly, string typeName, bool throwOnError, bool ignoreCase)
{
// Check if the type name specifies the assembly name
if(typeName.IndexOf(',') == -1)
{
//LogLog.Debug("SystemInfo: Loading type ["+typeName+"] from assembly ["+relativeAssembly.FullName+"]");
#if NETCF
return relativeAssembly.GetType(typeName, throwOnError);
#else
Type type=relativeAssembly.GetType(typeName, throwOnError, ignoreCase);
if (type!=null) return type;
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) {
type=assembly.GetType(typeName, false, ignoreCase);
if (type!=null) return type;
}
if (throwOnError) throw new TypeLoadException("Type '"+typeName+"' cannot be found");
else return null;
#endif
}
else
{
// Includes assembly name
//LogLog.Debug("SystemInfo: Loading type ["+typeName+"] from global Type");
#if NETCF
return Type.GetType(typeName, throwOnError);
#else
return Type.GetType(typeName, throwOnError, ignoreCase);
#endif
}
}
