public static IDbProvider GetProvider(string assName, Database db) { try { var asm = LoadAssembly(assName); //Type type = asm.GetExportedTypes().FirstOrDefault(p => TypeExt.IsClass(p) && typeof(IDbProvider).IsAssignableFrom(p)); Type type = null; Exception exg = null; foreach (Type _type in asm.GetExportedTypes()) { try { if (TypeExt.IsClass(_type) && typeof(IDbProvider).IsAssignableFrom(_type)) { type = _type; break; } } catch (Exception ex) { exg = ex; } } if (type != null) { IDbProvider prov = null; try { return((IDbProvider)Activator.CreateInstance(type, db)); } catch (Exception ex) { exg = new Exception("Erro on create " + type.Name); } } if (exg != null) { throw new Exception("Erro on loading assembly " + assName, exg); } else { throw new Exception("Erro on loading assembly " + assName); } } catch (Exception ex) { throw new Exception("Error loading assembly: " + assName, ex); } }
public static IDbProvider GetProvider(string assName, Database db) { try { var asm = LoadAssembly(assName); Type type = asm.GetExportedTypes().FirstOrDefault(p => TypeExt.IsClass(p) && typeof(IDbProvider).IsAssignableFrom(p)); return((IDbProvider)Activator.CreateInstance(type, db)); } catch (Exception ex) { throw new Exception("Error loading assembly: " + assName, ex); } }