/// <summary> /// Creates a deep clone of the source object. /// </summary> /// <param name="context">The deep cloning context.</param> /// <returns> /// A deep clone. /// </returns> public override NodeBase DeepClone(NodeCloningContext context) => new FunctionNodeReplace( FirstParameter.DeepClone(context), SecondParameter.DeepClone(context), ThirdParameter.DeepClone(context));
/// <summary> /// Creates a deep clone of the source object. /// </summary> /// <param name="context">The deep cloning context.</param> /// <returns> /// A deep clone. /// </returns> public override NodeBase DeepClone(NodeCloningContext context) => new FunctionNodeMinimum( FirstParameter.DeepClone(context), SecondParameter.DeepClone(context));
/// <summary> /// Generates the expression with tolerance that will be compiled into code. /// </summary> /// <param name="tolerance">The tolerance.</param> /// <returns>The expression.</returns> protected override Expression GenerateExpressionInternal(Tolerance?tolerance) { Type firstParameterType = typeof(string); Type secondParameterType = typeof(int); Type thirdParameterType = typeof(int); const string functionName = nameof(string.Substring); MethodInfo mi = typeof(string).GetMethodWithExactParameters( functionName, secondParameterType, thirdParameterType) !; if (mi == null) { throw new InvalidOperationException( string.Format( CultureInfo.CurrentCulture, Resources.FunctionCouldNotBeFound, functionName)); } Expression e1, e2, e3; if (tolerance == null) { e1 = FirstParameter.GenerateExpression(); e2 = SecondParameter.GenerateExpression(); e3 = ThirdParameter.GenerateExpression(); } else { e1 = FirstParameter.GenerateExpression(tolerance); e2 = SecondParameter.GenerateExpression(tolerance); e3 = ThirdParameter.GenerateExpression(tolerance); } if (e1.Type != firstParameterType) { e1 = Expression.Convert( e1, firstParameterType); } if (e2.Type != secondParameterType) { e2 = Expression.Convert( e2, secondParameterType); } if (e3.Type != thirdParameterType) { e3 = Expression.Convert( e3, thirdParameterType); } return(Expression.Call( e1, mi, e2, e3)); }