private Assembly OnCurrentDomainTypeResolve(object sender, ResolveEventArgs args) { var foundType = CurrentDomainTypes.GetTypes().FirstOrDefault(t => t.FullName == args.Name || t.Name == args.Name); if (foundType != null) { return(foundType.Assembly); } return(null); }
private static IDatabaseInitializer <TContext> TryGetInitializer <TContext>(TContext context) where TContext : ContextBase { var dbInitializerType = CurrentDomainTypes.GetChilrenClassesFromBinDirectory(typeof(DbInitializerBase <,>), true) .FirstOrDefault(t => t.BaseType != null && t.BaseType.GenericTypeArguments.Contains(context.GetType())); IDatabaseInitializer <TContext> dbInitializerInstance = null; if (dbInitializerType != null) { dbInitializerInstance = context.TryCastInitializer(Activator.CreateInstance(dbInitializerType)); } return(dbInitializerInstance); }
/// <summary> /// The list. /// </summary> /// <param name="count"> /// The count. /// </param> /// <typeparam name="T"> /// </typeparam> /// <returns> /// The <see cref="IEnumerable"/>. /// </returns> public static IEnumerable <T> List <T>(int count) where T : class, new() { var type = CurrentDomainTypes.GetTypesDerivingFrom <MockRepository <T> >(isIncludingAbstract: false).FirstOrDefault(); if (type == null) { return((IEnumerable <T>) new T()); } var instance = Activator.CreateInstance(type); var example = ((IMockRepository <T>)instance).List(count); return(example); }
private static IEnumerable <T> GetRegistrarInstances <T>(ILogger logger) { try { logger.Debug(() => string.Format("Look for {0} in the current domain", typeof(T))); var registrarTypes = CurrentDomainTypes.GetTypesDerivingFrom <T>(isIncludingAbstract: false); logger.Debug(() => string.Format("Found {0} types count {1}", typeof(T), registrarTypes.Count())); return(registrarTypes.Select(registrarType => (T)Activator.CreateInstance(registrarType)).ToList()); } catch (ReflectionTypeLoadException reflectionTypeLoadException) { logger.Fatal(reflectionTypeLoadException); throw; } }
/// <summary> /// Loads all types in the current domain and caches them /// </summary> /// <param name="logger"> /// Logger /// </param> private void LoadCurrentDomainTypes(ILogger logger) { if (logger == null) { throw new ArgumentNullException("logger"); } var entryAssembly = EnvironmentInfo.GetEntryAssembly(); if (entryAssembly != null) { logger.Debug(() => $"Add entry assembly to CurrentDomainTypes {entryAssembly.FullName}"); var assemblyName = entryAssembly.GetName(); CurrentDomainTypes.AddAssembly(assemblyName); } var loadedTypes = CurrentDomainTypes.GetTypes().ToList(); logger.Debug(() => $"Count of loaded types in actual domain {AppDomain.CurrentDomain.FriendlyName} {loadedTypes.Count}"); }
/// <summary> /// The scan for specification. /// </summary> /// <param name="isForce"> /// The is force. /// </param> public static void ScanForSpecification(bool isForce = false) { isForce = isForce || foundSpecifications == null; if (!isForce) { return; } var scanner = new SpecificationScanner(); scanner.AddAssemblies(CurrentDomainTypes.GetAssemblies().ToList()); var fieldSpecsFound = scanner.GetType().GetField("_specifications", BindingFlags.Instance | BindingFlags.NonPublic); foundSpecifications = (List <Type>)fieldSpecsFound.GetValue(scanner); if (foundSpecifications.Count == 0) { foundSpecifications.Add(typeof(DummySpecification)); } }