private static object _DoOperation(Func <Expression, Expression, BinaryExpression> exp, List <Opt> cache, object a, object b) { if (a != null && b != null) { Type type = a.GetType(); Type type2 = b.GetType(); try { if (type != typeof(string) && type2 != typeof(string)) { Opt opt = BloxMathsUtil.FindOpt(cache, type, type2); if (opt == null) { ParameterExpression parameterExpression = Expression.Parameter(type, "a"); ParameterExpression parameterExpression2 = Expression.Parameter(type2, "b"); Delegate @delegate = null; try { @delegate = Expression.Lambda(exp(parameterExpression, parameterExpression2), parameterExpression, parameterExpression2).Compile(); } catch (InvalidOperationException) { if (type != type2) { Expression arg = parameterExpression; Expression arg2 = Expression.Convert(parameterExpression2, type); @delegate = Expression.Lambda(exp(arg, arg2), parameterExpression, parameterExpression2).Compile(); goto end_IL_00a4; } throw; end_IL_00a4 :; } opt = new Opt { ta = type, tb = type2, comm = @delegate }; cache.Add(opt); } if (opt != null) { return(opt.comm.DynamicInvoke(a, b)); } goto end_IL_001f; } return(a.ToString() + b.ToString()); end_IL_001f :; } catch { throw new Exception(string.Format("The operation can't be completed with [{0}] and [{1}].", type, type2)); } return(null); } throw new Exception("The operation can't be completed since one or both values are null."); }
protected override object RunBlock() { object a = (base.paramBlocks[0] == null) ? null : base.paramBlocks[0].Run(); object b = (base.paramBlocks[1] == null) ? null : base.paramBlocks[1].Run(); try { return(BloxMathsUtil.RightShift(a, b)); } catch (Exception ex) { base.LogError(ex.Message, null); return(null); } }
public static object RightShift(object a, object b) { return(BloxMathsUtil._DoOperation(Expression.RightShift, BloxMathsUtil.rsCache, a, b)); }
public static object BitwiseXor(object a, object b) { return(BloxMathsUtil._DoOperation(Expression.ExclusiveOr, BloxMathsUtil.xorCache, a, b)); }
public static object BitwiseAnd(object a, object b) { return(BloxMathsUtil._DoOperation(Expression.And, BloxMathsUtil.andCache, a, b)); }
public static object Modulo(object a, object b) { return(BloxMathsUtil._DoOperation(Expression.Modulo, BloxMathsUtil.modCache, a, b)); }
public static object Divide(object a, object b) { return(BloxMathsUtil._DoOperation(Expression.Divide, BloxMathsUtil.divCache, a, b)); }
public static object Multiply(object a, object b) { return(BloxMathsUtil._DoOperation(Expression.Multiply, BloxMathsUtil.mulCache, a, b)); }
public static object Subtract(object a, object b) { return(BloxMathsUtil._DoOperation(Expression.Subtract, BloxMathsUtil.subCache, a, b)); }
public static object Add(object a, object b) { return(BloxMathsUtil._DoOperation(Expression.Add, BloxMathsUtil.addCache, a, b)); }