示例#1
0
 public SpecificationResult ApplyLabel(SetDefinitionTarget target, Label label)
 {
     return(new SpecificationResult(
                SymbolValue,
                SetDefinitions,
                Targets,
                labelByTarget.ContainsKey(target) ? labelByTarget : labelByTarget.Add(target, label)
                ));
 }
示例#2
0
 public SpecificationResult WithTarget(SetDefinitionTarget target)
 {
     return(new SpecificationResult(
                SymbolValue,
                SetDefinitions,
                Targets.Add(target),
                labelByTarget
                ));
 }
示例#3
0
 private static bool IsJoinTargeting(SetDefinition set, SetDefinitionTarget target)
 {
     if (set is SetDefinitionJoin joinSet)
     {
         return(joinSet.Tail.TargetSetDefinition == target);
     }
     else
     {
         return(false);
     }
 }
示例#4
0
 public Label GetLabelOf(SetDefinitionTarget target)
 {
     return(labelByTarget[target]);
 }
示例#5
0
 public bool TryGetLabelOf(SetDefinitionTarget target, [MaybeNullWhen(false)] out Label label)
 {
     return(labelByTarget.TryGetValue(target, out label));
 }
示例#6
0
        private static void ThrowSpecificationErrorWithoutLabel(SpecificationContext context, SpecificationResult result, SetDefinitionTarget?priorTarget, SetDefinitionTarget target)
        {
            string targetDescription;
            Type   targetType;
            string targetName;

            if (priorTarget == null)
            {
                var parameter = context.GetFirstVariable();
                targetDescription = $"parameter \"{parameter.Label.Name}\"";
                targetType        = parameter.Type;
                targetName        = parameter.Label.Name;
            }
            else if (result.TryGetLabelOf(priorTarget, out var priorLabel))
            {
                targetDescription = $"prior variable \"{priorLabel.Name}\"";
                targetType        = priorTarget.Type;
                targetName        = priorLabel.Name;
            }
            else
            {
                targetDescription = $"prior variable";
                targetType        = priorTarget.Type;
                targetName        = "x";
            }
            var typeName       = target.Type.Name;
            var variable       = ToInitialLowerCase(typeName);
            var message        = $"The set should be joined to the {targetDescription}.";
            var recommendation = RecommendationEngine.RecommendJoin(
                new CodeExpression(target.Type, variable),
                new CodeExpression(targetType, targetName)
                );

            throw new SpecificationException(recommendation == null ? message : $"{message} Consider \"facts.OfType<{typeName}>({variable} => {recommendation})\".");
        }