示例#1
0
        public static IfElseExpression IfElse(XzaarExpression test, XzaarExpression ifTrue, XzaarExpression ifFalse)
        {
            RequiresCanRead(test, "test");
            RequiresCanRead(ifTrue, "ifTrue");
            RequiresCanRead(ifFalse, "ifFalse");

            if (test.Type != XzaarBaseTypes.Boolean && test.Type != XzaarBaseTypes.Any)
            {
                throw new InvalidOperationException("Argument must be boolean");
            }


            // only true for the '??' operator, but we don't have that in XzaarScript (yet)

            //if (!XzaarTypeUtils.AreEquivalent(ifTrue.Type, ifFalse.Type))
            //{
            //    // throw Error.ArgumentTypesMustMatch();
            //    throw new InvalidOperationException("Argument types must match");
            //}

            return(IfElseExpression.Make(test, ifTrue, ifFalse, ifTrue.Type));
        }
示例#2
0
        public static IfElseExpression IfElse(XzaarExpression test, XzaarExpression ifTrue, XzaarExpression ifFalse, XzaarType type)
        {
            RequiresCanRead(test, "test");
            RequiresCanRead(ifTrue, "ifTrue");
            RequiresCanRead(ifFalse, "ifFalse");

            if (test.Type != XzaarBaseTypes.Boolean)
            {
                // throw Error.ArgumentMustBeBoolean();
                throw new InvalidOperationException("Argument must be boolean");
            }

            if (type != XzaarBaseTypes.Void)
            {
                if (!XzaarTypeUtils.AreReferenceAssignable(type, ifTrue.Type) ||
                    !XzaarTypeUtils.AreReferenceAssignable(type, ifFalse.Type))
                {
                    throw new InvalidOperationException("Argument types must match");
                }
            }

            return(IfElseExpression.Make(test, ifTrue, ifFalse, type));
        }