本文整理匯總了C#中System.Workflow.Activities.Rules.RuleValidation.FindBestCandidate方法的典型用法代碼示例。如果您正苦於以下問題:C# RuleValidation.FindBestCandidate方法的具體用法?C# RuleValidation.FindBestCandidate怎麽用?C# RuleValidation.FindBestCandidate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Workflow.Activities.Rules.RuleValidation
的用法示例。
在下文中一共展示了RuleValidation.FindBestCandidate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: MapOperatorToMethod
//.........這裏部分代碼省略.........
// enum specific operations already handled, see if one side (or both) define operators
AddOperatorOverloads(lhsType0, methodName, lhs, rhs, candidates);
AddOperatorOverloads(rhsType0, methodName, lhs, rhs, candidates);
if (lhsNullable || rhsNullable || (lhs == typeof(NullLiteral)) || (rhs == typeof(NullLiteral)))
{
// need to add in lifted methods
AddLiftedOperators(lhsType0, methodName, group, lhsType0, rhsType0, candidates);
AddLiftedOperators(rhsType0, methodName, group, lhsType0, rhsType0, candidates);
}
if (candidates.Count == 0)
{
// no overrides, so get the default list
methodName = methodName.Substring(3); // strip off the op_
foreach (MethodInfo mi in typeof(DefaultOperators).GetMethods())
{
if (mi.Name == methodName)
{
ParameterInfo[] parameters = mi.GetParameters();
Type parm1 = parameters[0].ParameterType;
Type parm2 = parameters[1].ParameterType;
if (RuleValidation.ImplicitConversion(lhs, parm1) &&
RuleValidation.ImplicitConversion(rhs, parm2))
{
candidates.Add(mi);
}
}
}
// if no candidates and ==, can we use object == object?
if ((candidates.Count == 0) && ("Equality" == methodName))
{
// C# 7.9.6
// references must be compatible
// no boxing
// value types can't be compared
if ((!lhs.IsValueType) && (!rhs.IsValueType))
{
// they are not classes, so references need to be compatible
// also check for null (which is NullLiteral type) -- null is compatible with any object type
if ((lhs == typeof(NullLiteral)) || (rhs == typeof(NullLiteral)) ||
(lhs.IsAssignableFrom(rhs)) || (rhs.IsAssignableFrom(lhs)))
{
candidates.Add(ObjectEquality);
}
}
}
// if no candidates and nullable, add lifted operators
if ((candidates.Count == 0) && ((lhsNullable || rhsNullable || (lhs == typeof(NullLiteral)) || (rhs == typeof(NullLiteral)))))
{
foreach (MethodInfo mi in typeof(DefaultOperators).GetMethods())
{
if (mi.Name == methodName)
{
ParameterInfo[] parameters = mi.GetParameters();
MethodInfo liftedMethod = EvaluateLiftedMethod(mi, parameters, group, lhsType0, rhsType0);
if (liftedMethod != null)
candidates.Add(liftedMethod);
}
}
}
}
if (candidates.Count == 1)
{
// only 1, so it is it
error = null;
return candidates[0];
}
else if (candidates.Count == 0)
{
// nothing matched
message = string.Format(CultureInfo.CurrentCulture,
(group == OperatorGrouping.Arithmetic) ? Messages.ArithOpBadTypes : Messages.RelationalOpBadTypes,
op.ToString(),
(lhs == typeof(NullLiteral)) ? Messages.NullValue : RuleDecompiler.DecompileType(lhs),
(rhs == typeof(NullLiteral)) ? Messages.NullValue : RuleDecompiler.DecompileType(rhs));
error = new ValidationError(message, ErrorNumbers.Error_OperandTypesIncompatible);
return null;
}
else
{
// more than 1, so pick the best one
MethodInfo bestFit = validator.FindBestCandidate(null, candidates, lhs, rhs);
if (bestFit != null)
{
error = null;
return bestFit;
}
// must be ambiguous. Since there are at least 2 choices, show only the first 2
message = string.Format(CultureInfo.CurrentCulture,
Messages.AmbiguousOperator,
op.ToString(),
RuleDecompiler.DecompileMethod(candidates[0]),
RuleDecompiler.DecompileMethod(candidates[1]));
error = new ValidationError(message, ErrorNumbers.Error_OperandTypesIncompatible);
return null;
}
}
示例2: MapOperatorToMethod
//.........這裏部分代碼省略.........
error = null;
return new EnumOperationMethodInfo(lhs, op, rhs, true);
}
if (!RuleValidation.TypesAreAssignable(type, type3, rhsExpression, out error))
{
break;
}
error = null;
return new EnumOperationMethodInfo(lhs, op, rhs, false);
}
error = null;
return new EnumOperationMethodInfo(lhs, op, rhs, false);
case CodeBinaryOperatorType.ValueEquality:
case CodeBinaryOperatorType.LessThan:
case CodeBinaryOperatorType.LessThanOrEqual:
case CodeBinaryOperatorType.GreaterThan:
case CodeBinaryOperatorType.GreaterThanOrEqual:
if (!(rhsType == type))
{
if (flag && (rhs == typeof(NullLiteral)))
{
error = null;
return new EnumOperationMethodInfo(lhs, op, lhs, false);
}
if (!DecimalIntegerLiteralZero(rhs, rhsExpression as CodePrimitiveExpression))
{
break;
}
error = null;
return new EnumOperationMethodInfo(lhs, op, rhs, true);
}
error = null;
return new EnumOperationMethodInfo(lhs, op, rhs, false);
}
}
AddOperatorOverloads(rhsType, str, lhs, rhs, candidates);
AddOperatorOverloads(type, str, lhs, rhs, candidates);
if ((flag || flag2) || ((lhs == typeof(NullLiteral)) || (rhs == typeof(NullLiteral))))
{
AddLiftedOperators(rhsType, str, arithmetic, rhsType, type, candidates);
AddLiftedOperators(type, str, arithmetic, rhsType, type, candidates);
}
if (candidates.Count == 0)
{
str = str.Substring(3);
foreach (MethodInfo info in typeof(DefaultOperators).GetMethods())
{
if (info.Name == str)
{
ParameterInfo[] parameters = info.GetParameters();
Type parameterType = parameters[0].ParameterType;
Type toType = parameters[1].ParameterType;
if (RuleValidation.ImplicitConversion(lhs, parameterType) && RuleValidation.ImplicitConversion(rhs, toType))
{
candidates.Add(info);
}
}
}
if ((((candidates.Count == 0) && ("Equality" == str)) && (!lhs.IsValueType && !rhs.IsValueType)) && (((lhs == typeof(NullLiteral)) || (rhs == typeof(NullLiteral))) || (lhs.IsAssignableFrom(rhs) || rhs.IsAssignableFrom(lhs))))
{
candidates.Add(ObjectEquality);
}
if ((candidates.Count == 0) && ((flag || flag2) || ((lhs == typeof(NullLiteral)) || (rhs == typeof(NullLiteral)))))
{
foreach (MethodInfo info2 in typeof(DefaultOperators).GetMethods())
{
if (info2.Name == str)
{
ParameterInfo[] infoArray2 = info2.GetParameters();
MethodInfo item = EvaluateLiftedMethod(info2, infoArray2, arithmetic, rhsType, type);
if (item != null)
{
candidates.Add(item);
}
}
}
}
}
if (candidates.Count == 1)
{
error = null;
return candidates[0];
}
if (candidates.Count == 0)
{
str2 = string.Format(CultureInfo.CurrentCulture, (arithmetic == OperatorGrouping.Arithmetic) ? Messages.ArithOpBadTypes : Messages.RelationalOpBadTypes, new object[] { op.ToString(), (lhs == typeof(NullLiteral)) ? Messages.NullValue : RuleDecompiler.DecompileType(lhs), (rhs == typeof(NullLiteral)) ? Messages.NullValue : RuleDecompiler.DecompileType(rhs) });
error = new ValidationError(str2, 0x545);
return null;
}
MethodInfo info4 = validator.FindBestCandidate(null, candidates, new Type[] { lhs, rhs });
if (info4 != null)
{
error = null;
return info4;
}
str2 = string.Format(CultureInfo.CurrentCulture, Messages.AmbiguousOperator, new object[] { op.ToString(), RuleDecompiler.DecompileMethod(candidates[0]), RuleDecompiler.DecompileMethod(candidates[1]) });
error = new ValidationError(str2, 0x545);
return null;
}