Dashing.Console.Program.LoadConfiguration C# (CSharp) Method

LoadConfiguration() private static method

private static LoadConfiguration ( Assembly configAssembly, DashingSettings dashingSettings, ConnectionStringSettings connectionStringSettings ) : object
configAssembly System.Reflection.Assembly
dashingSettings Dashing.Console.Settings.DashingSettings
connectionStringSettings Dashing.Console.Settings.ConnectionStringSettings
return object
        private static object LoadConfiguration(
            Assembly configAssembly,
            DashingSettings dashingSettings,
            ConnectionStringSettings connectionStringSettings) {
            // fetch the to state
            var configType = configAssembly.GetLoadableTypes().SingleOrDefault(t => t.FullName == dashingSettings.ConfigurationName);

            if (configType == null) {
                using (Color(ConsoleColor.Red)) {
                    var candidates = configAssembly.GetLoadableTypes().Where(t => t.GetInterface(typeof(IConfiguration).FullName) != null).ToArray();
                    if (candidates.Any()) {
                        throw new CatchyException(
                            "Could not locate {0}, but found candidates: {1}",
                            dashingSettings.ConfigurationName,
                            string.Join(", ", candidates.Select(c => c.FullName)));
                    }

                    throw new CatchyException("Could not locate {0}, and found no candidate configurations", dashingSettings.ConfigurationName);
                }
            }

            // attempt to find the call to ConfigurationManager and overwrite the connection string
            InjectConnectionString(dashingSettings, connectionStringSettings);

            // TODO add in a factory way of generating the config for cases where constructor not empty
            return Activator.CreateInstance(configType);
        }