CSE.Exps.CondExp.Ternary C# (CSharp) Method

Ternary() public static method

Parses ternary expressions
public static Ternary ( CseObject cond, CseObject truePart, CseObject falsePart ) : CseObject
cond CseObject Conditional to test
truePart CseObject Expression to return if condition is true
falsePart CseObject Expression to return if condition is false
return CseObject
		public static CseObject Ternary(CseObject cond, CseObject truePart, CseObject falsePart) {
			bool? condBool = cond.Value as bool?;

			if (condBool != null)
				return condBool.Value ? truePart : falsePart;
			else {
				MethodInfo mi = cond.Value.GetType().GetMethod(OpOverloadNames.TRUE);
				if (mi != null)
					return new CseObject(cond.Value.GetType().InvokeMember(OpOverloadNames.TRUE, OpOverloadNames.Flags, null, CsEval.evalEnvironment, new object[] { cond.Value }));
				else
					return null;
				//TODO: throw new logic exception for this 
			}
		}
	}