Beispiel #1
0
        public Expression MakeTestForTypes(Type[] types, int index)
        {
            Expression test = MakeTypeTest(types[index], index);

            if (index < types.Length - 1)
            {
                Expression nextTests = MakeTestForTypes(types, index + 1);
                if (ConstantCheck.Check(test, true))
                {
                    return(nextTests);
                }
                else if (ConstantCheck.Check(nextTests, true))
                {
                    return(test);
                }
                else
                {
                    return(Ast.AndAlso(test, nextTests));
                }
            }
            else
            {
                return(test);
            }
        }
Beispiel #2
0
        internal static bool CanAssign(Type to, Expression from) {
            if (CanAssign(to, from.Type)) return true;

            if (to.IsValueType() && 
                to.IsGenericType() && 
                to.GetGenericTypeDefinition() == typeof(Nullable<>) && 
                ConstantCheck.Check(from, null)) {
                return true;
            }

            return false;
        }