protected override Result DoEval(Evaluator evaluater, Result[] argArray) { Type type = typeof(int); int ret = System.Convert.ToInt32(argArray[0].Value) % System.Convert.ToInt32(argArray[1].Value); return(new Result(type, ConvertHelper.ChangeType(ret, type))); }
protected override Result DoEval(Evaluator evaluater, Result[] argArray) { Type type = argArray[0].Type; double ret = System.Convert.ToDouble(argArray[0].Value) / System.Convert.ToDouble(argArray[1].Value); return(new Result(type, ConvertHelper.ChangeType(ret, type))); }
protected override void ProcessArg(Evaluator evaluater, Result[] argArray) { base.ProcessArg(evaluater, argArray); Type type0 = argArray[0].Type; Type type1 = argArray[1].Type; int result; if (type0 == null || type1 == null) { throw new InvalidCastException(); } if (BinaryHelper.ComparePrimitiveType(type0, type1, out result)) { if (result > 0) { argArray[1].Value = ConvertHelper.ChangeType(argArray[1].Value, type0); } else if (result < 0) { argArray[0].Value = ConvertHelper.ChangeType(argArray[0].Value, type1); } } else { throw new InvalidCastException(string.Format("from {1} to {0}", type0.Name, type1.Name)); } }
protected override Result DoEval(Evaluator evaluater, Result[] argArray) { Type type0 = argArray[0].Type; Type type1 = argArray[1].Type; if (type0 == null && type1 == null) { return(new Result(null, null)); } else { if (type0 == typeof(string)) { return(new Result(ConvertHelper.ToString(argArray[0].Value) + ConvertHelper.ToString(argArray[1].Value))); } else { double ret = System.Convert.ToDouble(argArray[0].Value) + System.Convert.ToDouble(argArray[1].Value); return(new Result(type0, ConvertHelper.ChangeType(ret, type0))); } } }
internal override Result Eval(Evaluator evaluater, Result[] argArray) { return(new Result(typeof(int), ~((uint)ConvertHelper.ChangeType(argArray[0].Value, typeof(uint))))); }
internal override Result Eval(Evaluator evaluater, Result[] argArray) { if (argArray.Length < 2) { throw new ArgumentException(); } object target = argArray[0].Value; if (target == null) { throw new ArgumentException(); } int length = argArray.Length - 1; Type type = null; BindingFlags bindingFlags = BindingFlags.Default; if (target is Type) { type = (Type)target; target = null; bindingFlags = BindingFlags.Static; } else { type = target.GetType(); bindingFlags = BindingFlags.Instance; } bindingFlags = BindingFlags.Public; Type[] argTypeArray = new Type[length]; object[] argValueAry = new object[length]; for (int i = 0; i < length; i++) { argTypeArray[i] = argArray[i + 1].Type; argValueAry[i] = argArray[i + 1].Value; } Binder defaultBinder = Type.DefaultBinder; PropertyInfo pi = type.GetProperty("Item", bindingFlags, defaultBinder, null, argTypeArray, null); if (pi == null) { pi = type.GetProperty("Items", bindingFlags, defaultBinder, null, argTypeArray, null); } if (pi != null) { return(new Result(pi.PropertyType, pi.GetValue(target, argValueAry))); } if (target == null) { throw new ArgumentException(); } object ret; if (target is string) { string s = (string)target; int index = (int)ConvertHelper.ChangeType(argArray[1].Value, typeof(int)); ret = s[index]; return(new Result(typeof(char), ret)); } if (target is Array) { Array array = (Array)target; if (array.Rank != (argArray.Length - 1)) { throw new ArgumentException(); } int[] indices = new int[length]; for (int i = 0; i < length; i++) { indices[i] = (int)ConvertHelper.ChangeType(argArray[i + 1].Value, typeof(int)); } ret = array.GetValue(indices); if (ret != null) { return(new Result(ret.GetType(), ret)); } return(new Result(null, null)); } if (target is IList) { IList list = (IList)target; if (argArray.Length != 2) { throw new ArgumentException(); } int index = (int)ConvertHelper.ChangeType(argArray[1].Value, typeof(int)); ret = list[index]; if (ret != null) { return(new Result(ret.GetType(), ret)); } return(new Result(null, null)); } throw new ArgumentException(); }