static Indicator GetIndicatorInstanceFromAssembly(Assembly assembly, string indicatorFileName, out string errorMessage)
{
Type[] assemblyTypes = assembly.GetTypes();
foreach (Type typeAssembly in assemblyTypes)
{
if(typeAssembly.IsSubclassOf(typeof(Indicator)))
{
ConstructorInfo[] aConstructorInfo = typeAssembly.GetConstructors();
// Looking for an appropriate constructor
foreach (ConstructorInfo constructorInfo in aConstructorInfo)
{
ParameterInfo[] parameterInfo = constructorInfo.GetParameters();
if (constructorInfo.IsConstructor &&
constructorInfo.IsPublic &&
parameterInfo.Length == 1 &&
parameterInfo[0].ParameterType == typeof(SlotTypes))
{
try
{
errorMessage = string.Empty;
return (Indicator)constructorInfo.Invoke(new object[] { SlotTypes.NotDefined });
}
catch (Exception exc)
{
errorMessage = "ERROR: [" + indicatorFileName + "] " + exc.Message;
if(!string.IsNullOrEmpty(exc.InnerException.Message))
errorMessage += Environment.NewLine + "\t" + exc.InnerException.Message;
return null;
}
}
}
errorMessage = "ERROR: Cannot find an appropriate constructor for " + indicatorFileName + ".";
return null;
}
}
errorMessage = "ERROR: Cannot create an instance of an indicator from " + assembly.ToString() + ".";
return null;
}