/// Evaluate the operation against stack public void Eval(IEvaluationContext context, Stack <object> stack) { Type t = OperationHelper.ResolveType(context, _typeName); if (t == null) { throw new TypeLoadException("Failed to resolve type '" + _typeName + "'"); } stack.Push(t); }
/// Evaluate the operation against stack public void Eval(IEvaluationContext context, Stack <object> stack) { var p = stack.Pop(); Type t = OperationHelper.ResolveType(context, _typeName); if (t == null) { throw new TypeLoadException("Failed to resolve type '" + _typeName + "'"); } if (p == null) { stack.Push(false); } else { stack.Push(t.IsAssignableFrom(p.GetType())); } }
/// Evaluate the operation against stack public void Eval(IEvaluationContext context, Stack <object> stack) { string typeName = _typeName; object arrInit = null; int pc = _paramCount; object[] o = null; int c = 0; if (_isInitializerProvided) { arrInit = stack.Pop(); if (!(arrInit is System.Collections.IEnumerable)) { throw new InvalidOperationException("Invalid array initializer"); } bool empty = (typeName == "[]"); if ((arrInit is Array) && !empty) { c = ((Array)arrInit).Length; } else { Type tc = null; List <object> rr = new List <object>(); foreach (var array in (arrInit as System.Collections.IEnumerable)) { rr.Add(array); if (empty) { tc = Utils.CommonBase(array, tc); } } c = rr.Count; arrInit = rr; if (tc != null) { typeName = tc.FullName + "[]"; } } pc--; if (pc == 0) { o = new object[1] { c } } ; } if (pc > 0) { o = OperationHelper.PopArray(stack, pc); } object ret = null; if (string.IsNullOrEmpty(typeName)) { ret = arrInit; } else { var tn = OperationHelper.ResolveType(context, typeName); if (tn == null) { throw new TypeLoadException("Failed to resolve type '" + _typeName + "'"); } if (!tn.IsArray && _isInitializerProvided) { throw new InvalidOperationException("Initializers can only be provided to arrays"); } if (!Utils.TryCreateInstance(tn, o, context.AccessPrivate, out ret)) { throw new InvalidOperationException("Failed to create object of type '" + _typeName + "'"); } } if (_isInitializerProvided && !string.IsNullOrEmpty(typeName)) { if (o != null && o.Length != 0 && (int)o[0] != c) { throw new InvalidOperationException("Array initializer length does not match array size"); } var par = (Array)ret; var elType = par.GetType().GetElementType(); c = 0; foreach (var array in (System.Collections.IEnumerable)arrInit) { par.SetValue(Utils.To(elType, array), c++); } } stack.Push(ret); }