public static Condition ( |
||
test | An |
|
ifTrue | An |
|
ifFalse | An |
|
type | Type | A |
Результат |
public static ConditionalExpression Condition(Expression test, Expression ifTrue, Expression ifFalse, Type type)
{
RequiresCanRead(test, nameof(test));
RequiresCanRead(ifTrue, nameof(ifTrue));
RequiresCanRead(ifFalse, nameof(ifFalse));
ContractUtils.RequiresNotNull(type, nameof(type));
if (test.Type != typeof(bool))
{
throw Error.ArgumentMustBeBoolean(nameof(test));
}
if (type != typeof(void))
{
if (!TypeUtils.AreReferenceAssignable(type, ifTrue.Type) ||
!TypeUtils.AreReferenceAssignable(type, ifFalse.Type))
{
throw Error.ArgumentTypesMustMatch();
}
}
return ConditionalExpression.Make(test, ifTrue, ifFalse, type);
}
Expression::Condition ( |
public LambdaExpression CreateLambda(Type from, Type to) { var input = Ex.Parameter(from, "input"); var fromInfo = infos[from]; var toInfo = infos[to]; if (fromInfo <= toInfo) // Can make use of an implicit conversion { var block = Result(to, Ex.Convert(input, to)); var lambda = Ex.Lambda(block, input); return(lambda); } else // Cannot make use of an implicit conversion, bounds must be checked. Precision might be lost. { var block = Ex.Condition( Ex.MakeBinary(Et.AndAlso, Ex.MakeBinary(Et.GreaterThanOrEqual, input, Ex.Convert(Ex.Constant(toInfo.MinValue), from)), Ex.MakeBinary(Et.LessThanOrEqual, input, Ex.Convert(Ex.Constant(toInfo.MaxValue), from))), Result(to, Ex.Convert(input, to)), NoResult(to)); var lambda = Ex.Lambda(block, input); return(lambda); } }