internal void RegisterFunctions(Assembly assembly)
{
foreach(Type type in assembly.GetLoadableTypes())
{
// Not a class or abstract?
if(!type.IsClass || type.IsAbstract)
{
continue;
}
// Is the type not assignable from the function base class?
if(!typeof(MathExpressionFunction).IsAssignableFrom(type))
{
continue;
}
// Make sure there is at least one parameterless constructor.
ConstructorInfo[] constructors = type.GetConstructors();
ConstructorInfo constructor = constructors.FirstOrDefault(x => x.GetParameters().Length == 0);
if(constructor == null)
{
string message = string.Format("Function of type '{0}' has no parameterless constructor.", type.FullName);
throw new MathExpressionException(message);
}
// Register the function.
MathExpressionFunction function = Activator.CreateInstance(type) as MathExpressionFunction;
this.RegisterFunction(function);
}
}