public void Deserialize_When2CtorsWithSameArgCount_EvaluateCorrectOne() { Serializer s = new Serializer(typeof(CtorMock)); ObjectExpression expr = new ObjectExpression(); expr.ResultType = typeof(CtorMock); NumericExpression IDExpr = new NumericExpression("10"); ValueExpression StrExpr = new ValueExpression("name"); expr.ConstructorArguments.Add(IDExpr); expr.ConstructorArguments.Add(StrExpr); CtorArgTypeResolver resolver = new CtorArgTypeResolver(expr,s.Config); Type[] argTypes = resolver.ResolveTypes(); CollectionAssert.AreElementsEqual(new Type[] { typeof(int), typeof(string) }, argTypes); }
public void Deserialize_UseCorrectTypes_WhenParametersDefined() { Serializer s = new Serializer(typeof(CtorMock2)); ObjectExpression expr = new ObjectExpression(); expr.ResultType = typeof(CtorMock2); NumericExpression IDExpr = new NumericExpression("10"); ObjectExpression objExpr = new ObjectExpression(); objExpr.ConstructorArguments.Add(new ValueExpression("name")); expr.ConstructorArguments.Add(IDExpr); expr.ConstructorArguments.Add(objExpr); Type[] definedTypes = new Type[] { typeof(int), typeof(MyObject2) }; CtorArgTypeResolver resolver = new CtorArgTypeResolver(expr, s.Config, definedTypes); Type[] argTypes = resolver.ResolveTypes(); CollectionAssert.AreElementsEqual(new Type[] { typeof(long), typeof(MyObject2) }, argTypes); // Try to construct IDExpr.ResultType = typeof(long); objExpr.ResultType = typeof(MyObject2); Evaluator eval = new Evaluator(s.Config); object result = eval.Evaluate(expr); }
public virtual void Visit(NumericExpression expression) { OnValue(expression); }