public Faker(string pluginsPath, IFakerConfig config) { IBaseTypeGenerator pluginGenerator; List <Assembly> assemblies = new List <Assembly>(); generatedTypes = new Stack <Type>(); baseTypesGenerators = GeneratorsSetCreator.CreateBaseTypesGeneratorsDictionary(); genericTypesGenerators = GeneratorsSetCreator.CreateGenericTypesGeneratorsDictionary(baseTypesGenerators); arraysGenerators = GeneratorsSetCreator.CreateArraysGeneratorsDictionary(baseTypesGenerators, genericTypesGenerators); if (config == null) { customGenerators = new Dictionary <PropertyInfo, IBaseTypeGenerator>(); } else { customGenerators = config.Generators; } try { foreach (string file in Directory.GetFiles(pluginsPath, "*.dll")) { try { assemblies.Add(Assembly.LoadFile(file)); } catch (BadImageFormatException) { } catch (FileLoadException) { } } } catch (DirectoryNotFoundException) { } foreach (Assembly assembly in assemblies) { foreach (Type type in assembly.GetTypes()) { foreach (Type typeInterface in type.GetInterfaces()) { if (typeInterface.Equals(typeof(IBaseTypeGenerator))) { pluginGenerator = (IBaseTypeGenerator)Activator.CreateInstance(type); baseTypesGenerators.Add(pluginGenerator.GeneratedType, pluginGenerator); } } } } }
public Faker(string pluginsFolder, IFakerConfig config) { IBaseGenerator pluginGenerator; List <Assembly> assemblies = new List <Assembly>(); _generatedTypesStack = new Stack <Type>(); _baseGenerators = TypesGeneratorsInitialize.InitBaseGeneratorsDictionary(); _collectionGenerators = TypesGeneratorsInitialize.InitCollectionGeneratorsDictionary(_baseGenerators); _arrayGenerators = TypesGeneratorsInitialize.InitArrayGeneratorsDictionary(_baseGenerators); if (config == null) { _customGenerators = new Dictionary <PropertyInfo, IBaseGenerator>(); } else { _customGenerators = config.Generators; } try { foreach (string file in Directory.GetFiles(pluginsFolder, "*.dll")) { try { assemblies.Add(Assembly.LoadFile(new FileInfo(file).FullName)); } catch (BadImageFormatException) { } catch (FileLoadException) { } } } catch (DirectoryNotFoundException) { } var types = from assembly in assemblies from type in assembly.GetTypes() from typeInterface in type.GetInterfaces() where typeInterface.Equals(typeof(IBaseGenerator)) select type; foreach (var t in types) { pluginGenerator = (IBaseGenerator)Activator.CreateInstance(t); _baseGenerators.Add(pluginGenerator.GenerateType, pluginGenerator); } }
public static void Main(string[] args) { // FakerConfig fakerConfig = new FakerConfig(); // Настройка генерируемых случайных значений для конкретного поля // путем передачи собственного генератора для конкретного поля/свойства ConfigFaker(); // Faker faker = new Faker(fakerConfig); // создание объектов CreateObjects(faker); // вывод объектов OutputObjects(); // ожидание ввода Console.ReadLine(); }
public Faker(IFakerConfig config) : this(defaultPluginsPath, config) { }
public Faker(IFakerConfig config) : this(_defPluginsFolder, config) { }