/// <summary> /// Creates a new expression. /// </summary> /// <param name="generator">The expression generator to use.</param> /// <param name="expressionName">The name of the requested expression.</param> /// <param name="resultType">The desired result type of the expression.</param> /// <returns>A new requested expression or null if one could not be generated.</returns> public static Expression Generate(this IExpressionGenerator generator, string expressionName, Type resultType) { Contract.Requires(null != generator); Contract.Requires(!String.IsNullOrEmpty(expressionName)); Contract.Requires(null != resultType); var request = NewRequest(generator, expressionName, resultType); return(generator.Generate(request)); }
/// <summary> /// Creates a new expression. /// </summary> /// <param name="generator">The expression generator to use.</param> /// <param name="expressionName">The name of the requested expression.</param> /// <param name="input">The requested input for the expression.</param> /// <returns>A new requested expression or null if one could not be generated.</returns> public static Expression Generate(this IExpressionGenerator generator, string expressionName, Expression input) { Contract.Requires(generator != null); Contract.Requires(!String.IsNullOrEmpty(expressionName)); Contract.Requires(input != null); var request = NewRequest(generator, expressionName, input); return(generator.Generate(request)); }
/// <summary> /// Creates a new conversion expression. /// </summary> /// <param name="generator">The expression generator to use.</param> /// <param name="resultType">The desired result type of the expression to convert to.</param> /// <param name="input">The input expression to convert from.</param> /// <returns>A new requested conversion expression or null if one could not be generated.</returns> public static Expression GenerateConversion(this IExpressionGenerator generator, Type resultType, Expression input) { Contract.Requires(null != generator); Contract.Requires(null != resultType); Contract.Requires(null != input); var request = NewConversionRequest(generator, resultType, input); return(generator.Generate(request)); }
/// <summary> /// Creates a new expression. /// </summary> /// <param name="generator">The expression generator to use.</param> /// <param name="expressionName">The name of the requested expression.</param> /// <param name="inputExpressions">The requested inputs for the expression.</param> /// <returns>A new requested expression or null if one could not be generated.</returns> public static Expression Generate(this IExpressionGenerator generator, string expressionName, params Expression[] inputExpressions) { Contract.Requires(null != generator); Contract.Requires(!String.IsNullOrEmpty(expressionName)); Contract.Requires(null != inputExpressions); Contract.Requires(inputExpressions.Length != 0); Contract.Requires(Contract.ForAll(inputExpressions, x => x != null)); var request = NewRequest(generator, expressionName, inputExpressions); return(generator.Generate(request)); }
/// <summary> /// Creates a new conversion expression. /// </summary> /// <param name="generator">The expression generator to use.</param> /// <param name="resultType">The desired result type of the expression to convert to.</param> /// <param name="input">The input expression to convert from.</param> /// <returns>A new requested conversion expression or null if one could not be generated.</returns> public static Expression GenerateConversionOrThrow(this IExpressionGenerator generator, Type resultType, Expression input) { Contract.Requires(null != generator); Contract.Requires(null != resultType); Contract.Requires(null != input); var request = NewConversionRequest(generator, resultType, input); var result = generator.Generate(request); if (result == null) { throw InvalidOpConversion(input.Type, resultType); } return(result); }
/// <summary> /// Creates a new expression. /// </summary> /// <param name="generator">The expression generator to use.</param> /// <param name="expressionName">The name of the requested expression.</param> /// <param name="resultType">The desired result type of the expression.</param> /// <returns>A new requested expression or null if one could not be generated.</returns> public static Expression GenerateOrThrow(this IExpressionGenerator generator, string expressionName, Type resultType) { Contract.Requires(null != generator); Contract.Requires(!String.IsNullOrEmpty(expressionName)); Contract.Requires(null != resultType); Contract.Ensures(Contract.Result <Expression>() != null); var request = NewRequest(generator, expressionName, resultType); var result = generator.Generate(request); if (result == null) { throw InvalidOp(expressionName, resultType); } return(result); }
/// <summary> /// Creates a new expression. /// </summary> /// <param name="generator">The expression generator to use.</param> /// <param name="expressionName">The name of the requested expression.</param> /// <param name="inputExpressions">The requested inputs for the expression.</param> /// <returns>A new requested expression or null if one could not be generated.</returns> public static Expression GenerateOrThrow(this IExpressionGenerator generator, string expressionName, params Expression[] inputExpressions) { Contract.Requires(null != generator); Contract.Requires(!String.IsNullOrEmpty(expressionName)); Contract.Requires(null != inputExpressions); Contract.Requires(inputExpressions.Length != 0); Contract.Requires(Contract.ForAll(inputExpressions, x => x != null)); Contract.Ensures(Contract.Result <Expression>() != null); var request = NewRequest(generator, expressionName, inputExpressions); var result = generator.Generate(request); if (result == null) { throw InvalidOp(expressionName, inputExpressions); } return(result); }
/// <summary> /// Creates a new expression. /// </summary> /// <param name="generator">The expression generator to use.</param> /// <param name="expressionName">The name of the requested expression.</param> /// <param name="input0">The first input argument.</param> /// <param name="input1">The second input argument.</param> /// <returns>A new requested expression or null if one could not be generated.</returns> public static Expression GenerateOrThrow(this IExpressionGenerator generator, string expressionName, Expression input0, Expression input1) { Contract.Requires(null != generator); Contract.Requires(!String.IsNullOrEmpty(expressionName)); Contract.Requires(input0 != null); Contract.Requires(input1 != null); Contract.Ensures(Contract.Result <Expression>() != null); var inputs = new[] { input0, input1 }; var request = NewRequest(generator, expressionName, inputs); var result = generator.Generate(request); if (result == null) { throw InvalidOp(expressionName, inputs); } return(result); }
public IEnumerable <IExpression> GetExpressions(int count, int goodCount) { List <IExpression> expressions = new List <IExpression>(count); while (count-- > 0) { int neededResult = _questionNumber; if (goodCount-- <= 0) { neededResult = GetSpreaded(neededResult, _mode.WrongScater); } IExpression expression = _generator.Generate(neededResult); if (expression == null) { throw new InvalidOperationException("not posible generate expression for on this mode: " + _mode.ToString()); } expressions.Add(expression); } expressions.Sort((e1, e2) => Random.Range(-1, 2)); return(expressions); }