public static int?GetScore(this IScoreEvaluator This, Type candidateType, VariantSet candidateVariants, VariantSet candidateImplicitVariants, Type requestedType, VariantSet requestedVariants) => This.GetVariantScore(requestedVariants, candidateVariants, candidateImplicitVariants) + This.GetTypeScore(requestedType, candidateType);
private Uri ResolvePrefabFromViewType(Type viewType, VariantSet requestedVariants) { var candidates = _manifest.ViewsToPrefabs .Where(x => viewType == x.Source) .ToList(); var resolved = candidates .Select(candidate => new CandidateMapping <TypeToUriMapping>(candidate, _scoreEvaluator.GetVariantScore(requestedVariants, candidate.Variants, VariantSet.Empty))) .Where(candidate => candidate.Score.HasValue) .WithMax(candidate => candidate.Score.Value) ?.Mapping; if (resolved == null) { throw new InvalidOperationException($"Failed to resolve View {viewType} to some Prefab (Variants: {requestedVariants})"); } if (Log.IsDebugEnabled) { Log.Debug($"Resolved View {viewType} to Prefab {resolved.Target} (Variants: {resolved.Variants})"); } if (candidates.Count > 1 && Log.IsDebugEnabled) { Log.Debug($"Other candidates were:{Environment.NewLine}" + $"{candidates.Except(resolved).JoinAsString(Environment.NewLine)}"); } return(resolved.Target); }