73 lines
3.0 KiB
C#
73 lines
3.0 KiB
C#
using System;
|
|
using System.Configuration;
|
|
using System.Threading;
|
|
using System.Xml;
|
|
namespace SPSolutions.Configuration
|
|
{
|
|
public class ConfigUtil
|
|
{
|
|
public static void CheckAssignableType(Type baseType, Type type, ConfigurationElement configElement, string propertyName)
|
|
{
|
|
if (!baseType.IsAssignableFrom(type))
|
|
{
|
|
throw new ConfigurationErrorsException("Type_doesnt_inherit_from_type", configElement.ElementInformation.Properties[propertyName].Source, configElement.ElementInformation.Properties[propertyName].LineNumber);
|
|
}
|
|
}
|
|
public static void CheckAssignableType(Type baseType, Type baseType2, Type type, ConfigurationElement configElement, string propertyName)
|
|
{
|
|
if (!baseType.IsAssignableFrom(type) && !baseType2.IsAssignableFrom(type))
|
|
{
|
|
throw new ConfigurationErrorsException("Type_doesnt_inherit_from_type", configElement.ElementInformation.Properties[propertyName].Source, configElement.ElementInformation.Properties[propertyName].LineNumber);
|
|
}
|
|
}
|
|
public static void CheckBaseType(Type expectedBaseType, Type userBaseType, string propertyName, ConfigurationElement configElement)
|
|
{
|
|
if (!expectedBaseType.IsAssignableFrom(userBaseType))
|
|
{
|
|
throw new ConfigurationErrorsException("Invalid_type_to_inherit_from", configElement.ElementInformation.Properties[propertyName].Source, configElement.ElementInformation.Properties[propertyName].LineNumber);
|
|
}
|
|
}
|
|
internal static Type GetType(string typeName, XmlNode node)
|
|
{
|
|
return ConfigUtil.GetType(typeName, node, false);
|
|
}
|
|
internal static Type GetType(string typeName, string propertyName, ConfigurationElement configElement)
|
|
{
|
|
return ConfigUtil.GetType(typeName, propertyName, configElement, true);
|
|
}
|
|
internal static Type GetType(string typeName, XmlNode node, bool ignoreCase)
|
|
{
|
|
return ConfigUtil.GetType(typeName, null, null, node, true, ignoreCase);
|
|
}
|
|
internal static Type GetType(string typeName, string propertyName, ConfigurationElement configElement, bool checkAptcaBit)
|
|
{
|
|
return ConfigUtil.GetType(typeName, propertyName, configElement, checkAptcaBit, false);
|
|
}
|
|
internal static Type GetType(string typeName, string propertyName, ConfigurationElement configElement, bool checkAptcaBit, bool ignoreCase)
|
|
{
|
|
return ConfigUtil.GetType(typeName, propertyName, configElement, null, checkAptcaBit, ignoreCase);
|
|
}
|
|
internal static Type GetType(string typeName, string propertyName, ConfigurationElement configElement, XmlNode node, bool checkAptcaBit, bool ignoreCase)
|
|
{
|
|
Type type;
|
|
try
|
|
{
|
|
type = Type.GetType(typeName, true, ignoreCase);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
|
|
{
|
|
throw;
|
|
}
|
|
if (node != null)
|
|
{
|
|
throw new ConfigurationErrorsException(ex.Message, ex, node);
|
|
}
|
|
throw new ConfigurationErrorsException(ex.Message, ex, configElement.ElementInformation.Properties[propertyName].Source, configElement.ElementInformation.Properties[propertyName].LineNumber);
|
|
}
|
|
return type;
|
|
}
|
|
}
|
|
}
|