private void Next_parts_should_contain(string expectedNextPart, Type expectedNextType, string args) { var nextParts = propPathBuilder.Next(startsWith); nextParts.Should().NotBeNullOrEmpty(); var found = nextParts.FirstOrDefault(pt => pt.Path == expectedNextPart); found.Should().NotBeNull(); var argValues = args.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); found !.ArgumentCount.Should().Be(argValues.Length); if (argValues.Length > 0) { var contextType = typeof(Device); var contextParameter = Expression.Parameter(contextType, "ctx"); var functionExpr = expectedNextPart.Replace("()", $"({args})"); var currentPath = string.IsNullOrEmpty(startsWith) ? functionExpr : $"{startsWith}.{functionExpr}"; var targetExpression = contextParameter.EvaluateExpression(currentPath); targetExpression.Type.Should().Be(expectedNextType); } else { found !.Type.Should().Be(expectedNextType); } }
///<summary> /// Check if the current instance equals another instance of this class. ///</summary> ///<param name="obj">The instance to compare the current instance with.</param> ///<returns><code>true</code> if the instances are the same instance or have the same content.</returns> public override bool Equals(Object obj) { if (obj == null || GetType() != obj.GetType()) { return(false); } DataOperation d = (DataOperation)obj; if (!ID.Equals(d.ID)) { return(false); } if (!ArgumentCount.Equals(d.ArgumentCount)) { return(false); } for (int i = 0; i < ArgumentCount; i++) { if (!GetArgument(i).Equals(d.GetArgument(i))) { return(false); } } return(true); }
public override string /*!*/ ToString() { return("(" + (HasImplicitSelf ? "." : "") + (HasScope ? "S," : "C,") + ArgumentCount.ToString() + (HasSplattedArgument ? "*" : "") + (HasBlock ? "&" : "") + (HasRhsArgument ? "=" : "") + ")"); }
public override string /*!*/ ToString() { return("(" + (HasImplicitSelf ? "." : "") + (HasImplicitArguments ? "^" : "") + (IsVirtualCall ? "V" : "") + (HasScope ? "S" : "C") + (ResolveOnly ? "?" : "," + ArgumentCount.ToString()) + (HasSplattedArgument ? "*" : "") + (HasBlock ? "&" : "") + (HasRhsArgument ? "=" : "") + ")"); }
/// <summary> /// Runs the code in the function, given the required arguments. /// </summary> /// <param name="args">Arguments used by function</param> /// <returns>The return value once the function completes</returns> public IResultValue Invoke(params IResultValue[] args) { if (args.Length != ArgumentCount) { throw new TargetInvocationException( "Argument count mismatched. Needs " + ArgumentCount.ToString() + ", got " + args.Length, null); } object[] argvals = new object[ArgumentCount]; for (int i = 0; i < ArgumentCount; i++) { Type argType = Function.GetMethodInfo().GetParameters()[i].ParameterType; if (argType == typeof(float)) { argvals[i] = Convert.ToSingle(args[i].CoreValue); } else if (argType == typeof(double)) { argvals[i] = Convert.ToDouble(args[i].CoreValue); } else if (argType == typeof(short)) { argvals[i] = Convert.ToInt16(args[i].CoreValue); } else if (argType == typeof(int)) { argvals[i] = Convert.ToInt32(args[i].CoreValue); } else { argvals[i] = args[i].CoreValue; } } object res = Function.DynamicInvoke(argvals); if (res is decimal || res is double || res is float) { return(new ResultNumberReal(Convert.ToDecimal(res))); } if (res is long || res is int || res is short) { return(new ResultNumberInteger(Convert.ToInt64(res))); } else if (res is string) { return(new ResultString(res as string)); } else if (res is bool) { return(new ResultBoolean(Convert.ToBoolean(res))); } else if (res is MathMatrix) { return(null); } else { throw new NotSupportedException( "Return type is of invalid Type: " + res.GetType().ToString()); } }