示例#1
0
        public string AsCastString(IValue val, [PexAssumeNotNull] Type desType)
        {
            if (desType == null)
            {
                throw new ArgumentException("destype must not be null");
            }
            string result = VarUtils.CastToType(val, Expression.Variable(desType, "d"));

            Assert.IsTrue(result.Contains("(("), "Result doesn't seem to contains the cast operator!");
            return(result);
        }
示例#2
0
        public string CastToType(int sourceTypeSpec, int destTypeSpec)
        {
            IValue sourceType = null;

            switch (sourceTypeSpec)
            {
            case 0:
                sourceType = new ValSimple("10", typeof(int));
                break;

            case 1:
                sourceType = new ValSimple("10.0", typeof(double));
                break;

            default:
                return("");
            }

            Type destType = null;

            switch (destTypeSpec)
            {
            case 0:
                destType = typeof(int);
                break;

            case 1:
                destType = typeof(double);
                break;

            default:
                return("");
            }

            string result = VarUtils.CastToType(sourceType, Expression.Variable(destType, "d"));

            if (destType == sourceType.Type ||
                sourceType.Type == typeof(float) && destType == typeof(double))
            {
                Assert.IsFalse(result.Contains("(("), "More that '((' in the list of items ('" + result + "')");
            }
            else
            {
                Assert.IsTrue(result.Contains("(("), "Incorrect number of  '((' in the list of items ('" + result + "') - expecting a cast from '" + sourceType.Type.Name + " to " + destType.Name + "'!");
            }
            return(result);
        }