ResolveCast() 공개 메소드

public ResolveCast ( IType targetType, ResolveResult expression ) : ResolveResult
targetType IType
expression ResolveResult
리턴 ResolveResult
예제 #1
0
        public void Addition()
        {
            TestOperator(MakeResult(typeof(short)), BinaryOperatorType.Add, MakeResult(typeof(byte?)),
                         Conversion.ImplicitNullableConversion, Conversion.ImplicitNullableConversion, typeof(int?));

            AssertConstant(3.0, resolver.ResolveBinaryOperator(
                               BinaryOperatorType.Add, MakeConstant(1.0f), MakeConstant(2.0)));

            AssertConstant("Text", resolver.ResolveBinaryOperator(
                               BinaryOperatorType.Add, MakeConstant("Te"), MakeConstant("xt")));

            AssertConstant("", resolver.ResolveBinaryOperator(
                               BinaryOperatorType.Add, MakeConstant(null), resolver.ResolveCast(ResolveType(typeof(string)), MakeConstant(null))));

            AssertError(typeof(ReflectionHelper.Null), resolver.ResolveBinaryOperator(
                            BinaryOperatorType.Add, MakeConstant(null), MakeConstant(null)));

            TestOperator(MakeResult(typeof(int?)), BinaryOperatorType.Add, MakeResult(typeof(uint?)),
                         Conversion.ImplicitNullableConversion, Conversion.ImplicitNullableConversion, typeof(long?));

            TestOperator(MakeResult(typeof(ushort?)), BinaryOperatorType.Add, MakeResult(typeof(ushort?)),
                         Conversion.ImplicitNullableConversion, Conversion.ImplicitNullableConversion, typeof(int?));

            TestOperator(MakeConstant(1), BinaryOperatorType.Add, MakeConstant(null),
                         Conversion.ImplicitNullableConversion, Conversion.NullLiteralConversion, typeof(int?));
        }
예제 #2
0
        void TestCast(Type targetType, ResolveResult input, Conversion expectedConversion)
        {
            IType         type = compilation.FindType(targetType);
            ResolveResult rr   = resolver.ResolveCast(type, input);

            AssertType(targetType, rr);
            Assert.AreEqual(typeof(ConversionResolveResult), rr.GetType());
            var crr = (ConversionResolveResult)rr;

            Assert.AreEqual(expectedConversion, crr.Conversion, "ConversionResolveResult.Conversion");
            Assert.AreSame(input, crr.Input, "ConversionResolveResult.Input");
        }
		public override ResolveResult Resolve(CSharpResolver resolver)
		{
			return resolver.ResolveCast(targetType.Resolve(resolver.CurrentTypeResolveContext), expression.Resolve(resolver));
		}
예제 #4
0
		public override ResolveResult Resolve(CSharpResolver resolver)
		{
			var type = targetType.Resolve(resolver.CurrentTypeResolveContext);
			var resolveResult = expression.Resolve(resolver);
			if (allowNullableConstants && NullableType.IsNullable(type)) {
				resolveResult = resolver.ResolveCast(NullableType.GetUnderlyingType(type), resolveResult);
				if (resolveResult.IsCompileTimeConstant)
					return new ConstantResolveResult(type, resolveResult.ConstantValue);
			}
			return resolver.ResolveCast(type, resolveResult);
		}