/// <summary> /// Collects types decorated with <see cref="AddToServicesAttribute"/> and user the <paramref name="applier"/> to apply it. /// </summary> /// <param name="applier">The applier to use.</param> /// <param name="tag">The tag to collect.</param> /// <exception cref="System.ArgumentNullException"><paramref name="applier"/> is null.</exception> public void Collect(IApplier applier, string tag = null) { if (applier == null) { throw new ArgumentNullException(nameof(applier)); } var implementations = Assemblies .SelectMany(a => a.ExportedTypes) .Where(t => t.GetTypeInfo() .CustomAttributes .Any(cd => cd.AttributeType == typeof(AddToServicesAttribute))); foreach (var implementation in implementations) { var attributes = implementation.GetTypeInfo().GetCustomAttributes <AddToServicesAttribute>(); foreach (var attribute in attributes) { if ((attribute.InternalTags == null && tag != null) || (attribute.InternalTags != null && tag == null) || (attribute.InternalTags != null && tag != null && !attribute.InternalTags.Any( t => t.Equals(tag, StringComparison.OrdinalIgnoreCase)))) { continue; } var context = new ApplierContext(implementation, attribute); applier.Apply(context); } } }
/// <summary> /// Collects types decorated with <see cref="AddToServicesAttribute"/> and user the <paramref name="applier"/> to apply it. /// </summary> /// <param name="applier">The applier to use.</param> /// <param name="tag">The tag to collect.</param> /// <exception cref="ArgumentNullException"><paramref name="applier"/> is null.</exception> public void Collect(IApplier applier, string tag = null) { if (applier == null) { throw new ArgumentNullException(nameof(applier)); } var pairs = _provider.GetAttributes(); foreach (var pair in pairs) { var implementation = pair.Implementation; var attributes = pair.Attributes; foreach (var attribute in attributes) { if ((attribute.InternalTags == null && tag != null) || (attribute.InternalTags != null && tag == null) || (attribute.InternalTags != null && tag != null && !attribute.InternalTags.Any( t => t.Equals(tag, StringComparison.OrdinalIgnoreCase)))) { continue; } var service = ValidateService(implementation, attribute); var context = new ApplierContext(service, implementation, attribute.ForwardTo, attribute.Lifetime); applier.Apply(context); } } }
/// <inheritdoc /> public TMove Calculate(TState state) { var moves = _moveGenerator.Generate(state).ToList(); if (!moves.Any()) { return(null); } var movesAndValues = moves.Select(move => new { Move = move, Value = _evaluator.Evaluate(_moveApplier.Apply(state, move)) }).ToList(); var min = movesAndValues.Min(x => x.Value); var result = movesAndValues.First(x => Equals(x.Value, min)).Move; return(result); }