private void Initialize() { if (!Directory.Exists(path)) { string currentAssemblyPath = Path.Combine(GetCurrentAssemblyPath(), "../"); string specialPath = currentAssemblyPath+path; if (!Directory.Exists(specialPath)) { int nbFolder = Directory.EnumerateDirectories(currentAssemblyPath).Count(); int nbFile = Directory.EnumerateFiles(currentAssemblyPath).Count(); int nbFiledll = Directory.EnumerateFiles(currentAssemblyPath, "*.dll").Count(); var toAddStatic = new Morpion.MorpionManager(); datas.Add(toAddStatic.GetGameType(), toAddStatic); var toAddStatic2 = new ChessService.ChessManager(); datas.Add(toAddStatic2.GetGameType(), toAddStatic2); var toAddStatic3 = new ConnectFour.ConnectFourManager(); datas.Add(toAddStatic3.GetGameType(), toAddStatic3); return; //throw new ArgumentException(String.Format("The folder in config does not exist ({0}),spePatch={2}, current folder = {1}, nbFolder{3}, nbFile{4}, nbdll{5}", path, Environment.CurrentDirectory, specialPath,nbFolder,nbFile,nbFiledll)); } else { path = specialPath; } } List<string> allAssembliesToLoad = GetAllFilesToLoad(path); foreach (string assemblyPath in allAssembliesToLoad) { //var assembly = Assembly.LoadFrom(assemblyPath); Assembly assembly = Assembly.Load(AssemblyName.GetAssemblyName(assemblyPath)); Type typeMatch = null; foreach (Type currentType in assembly.GetTypes()) { if (currentType.GetInterface(typeof(IGameServices).FullName, false) != null) { if (typeMatch != null) { throw new Exception(string.Format("The assembly [{0}] contains more than two type implementing IGameInterface")); } else { typeMatch = currentType; } } } if (typeMatch == null) { //No type found? } else { // Instance dynamique à partir du type donné object objInstanceDynamique = System.Activator.CreateInstance(typeMatch); var myGame = objInstanceDynamique as IGameServices; if (myGame != null) { if (!datas.ContainsKey(myGame.GetGameType())) { datas.Add(myGame.GetGameType(), myGame); } else { //already added? } } } } }