private void ScanAndLoad(string path) { Logger.Debug("Loading assembly from : {0}", path); Assembly assembly; try { // Load assembly for reflection only to avoid exceptions when referenced assemblyLocations cannot be found assembly = _assemblyWrapper.ReflectionOnlyLoadFrom(path); } catch { Logger.Warn("Failed to scan assembly {0}", path); return; } var isReferencingGaugeLib = assembly.GetReferencedAssemblies() .Select(name => name.Name) .Contains(typeof(Step).Assembly.GetName().Name); var loadableTypes = new HashSet <Type>(isReferencingGaugeLib ? GetLoadableTypes(assembly) : new Type[] {}); // Load assembly so that code can be executed var fullyLoadedAssembly = _assemblyWrapper.LoadFrom(path); var types = GetFullyLoadedTypes(loadableTypes, fullyLoadedAssembly).ToList(); if (isReferencingGaugeLib) { AssembliesReferencingGaugeLib.Add(fullyLoadedAssembly); } ScanForScreengrabber(types); ScanForInstanceManager(types); }
public List <MethodInfo> GetMethods(Type annotationType) { Func <MethodInfo, bool> methodFilter = info => info.GetCustomAttributes() .Any(a => a.GetType().FullName.Equals(annotationType.FullName)); Func <Type, IEnumerable <MethodInfo> > methodSelector = t => t.GetMethods().Where(methodFilter); return(AssembliesReferencingGaugeLib.SelectMany(assembly => assembly.GetTypes().SelectMany(methodSelector)).ToList()); }
public List <MethodInfo> GetMethods(Type annotationType) { var typeFromTargetLib = GetTypeFromTargetLib(annotationType); Func <MethodInfo, bool> methodFilter = info => info.GetCustomAttributes(typeFromTargetLib).Any(); Func <Type, IEnumerable <MethodInfo> > methodSelector = t => t.GetMethods().Where(methodFilter); return(AssembliesReferencingGaugeLib.SelectMany(assembly => assembly.GetTypes().SelectMany(methodSelector)).ToList()); }
public IEnumerable <MethodInfo> GetMethods(LibType type) { var attributeType = _targetLibAssembly.GetType(type.FullName()); bool methodFilter(MethodInfo info) => info.GetCustomAttributes(false) .Any(attributeType.IsInstanceOfType); IEnumerable <MethodInfo> methodSelector(Type t) => _reflectionWrapper.GetMethods(t).Where(methodFilter); return(AssembliesReferencingGaugeLib.SelectMany(assembly => assembly.GetTypes().SelectMany(methodSelector))); }
public IEnumerable <MethodInfo> GetMethods(LibType type) { var attributeType = _targetLibAssembly.ExportedTypes.First(x => x.FullName == type.FullName()); IEnumerable <MethodInfo> MethodSelector(Type t) { return(_reflectionWrapper.GetMethods(t) .Where(info => info.GetCustomAttributes(false).Any(attributeType.IsInstanceOfType))); } return(AssembliesReferencingGaugeLib.SelectMany(assembly => assembly.ExportedTypes.SelectMany(MethodSelector))); }
private void ScanAndLoad(string path) { Logger.Debug($"Loading assembly from : {path}"); var assembly = _assemblyWrapper.LoadFrom(path); var isReferencingGaugeLib = assembly.GetReferencedAssemblies() .Select(name => name.Name) .Contains(GaugeLibAssembleName); if (!isReferencingGaugeLib) { return; } AssembliesReferencingGaugeLib.Add(assembly); try { if (ScreenshotWriter is null) { ScanForCustomScreenshotWriter(assembly.GetTypes()); } if (ScreenshotWriter is null) { ScanForCustomScreengrabber(assembly.GetTypes()); } if (ClassInstanceManagerType is null) { ScanForCustomInstanceManager(assembly.GetTypes()); } } catch (ReflectionTypeLoadException ex) { foreach (var e in ex.LoaderExceptions) { Logger.Error(e.ToString()); } } }