FromFiles() public static method

public static FromFiles ( Type configurationType, IEnumerable fileInfo ) : ConfigurationPart
configurationType System.Type
fileInfo IEnumerable
return ConfigurationPart
Ejemplo n.º 1
0
        public void Load()
        {
            var previousConfigurations    = Configurations;
            var markerType                = typeof(Marker);
            var filesForEachConfiguration = _configurationDirectories.SelectMany(c => c.GetFiles())
                                            .Where(f => FullTypeNameDeclaration.IsMatch(f.Name))
                                            .GroupBy(c => Type.GetType(c.Name, false, true) ?? markerType)
                                            .ToDictionary(g => g.Key);

            if (filesForEachConfiguration.ContainsKey(markerType))
            {
                var message = string.Format("No types found for files {0}",
                                            string.Join(", ", filesForEachConfiguration[markerType].Select(f => f.FullName).ToArray()));
                throw new InvalidOperationException(message);
            }

            Configurations = filesForEachConfiguration
                             .Select((filesForType) => ConfigurationPart.FromFiles(filesForType.Key, filesForType.Value))
                             .Where(r => r != null)
                             .ToList();

            _container.Compose(new CompositionBatch(Configurations, previousConfigurations));
        }