public override object Visit(MethodNode obj) { object instance; if (obj.Variable != null) { instance = obj.Variable.Accept(this); } else { instance = _ctx.Resolve("this");//Note:treat it as part of host class } string methodName = (obj.Method as SimpleNode).Token.TokenValue; object[] paramArray = (object[])obj.Args.Accept(this); if (instance == null) { ExceptionHelper.ThrowEvalNull(); } ISmartInvoker invoker; ClassDefination cdef = instance as ClassDefination; if (cdef != null) { invoker = EvalSmartInvoker.CreateInstance(cdef.ObjType, false); } else { invoker = EvalSmartInvoker.CreateInstance(instance, true); } return(invoker.Invoke(methodName, paramArray)); }
public override object Visit(IndexerNode obj) { object instance = obj.Variable.Accept(this); object[] paramArray = (object[])obj.Args.Accept(this); if (instance == null) { ExceptionHelper.ThrowEvalNull(); } ISmartInvoker invoker; ClassDefination cdef = instance as ClassDefination; if (cdef != null) { invoker = EvalSmartInvoker.CreateInstance(cdef.ObjType, false); } else { invoker = EvalSmartInvoker.CreateInstance(instance, true); } if (instance.GetType().IsArray)//Note:invoke "Get" on array { return(invoker.Invoke("Get", paramArray)); } else//Note:invoke indexer on instance { try//Note:Try indexer first { return(invoker.Invoke("get_Item", paramArray)); } catch//Note:then try property { if (paramArray.Length == 1 && paramArray[0] != null) { string propertyName = paramArray[0].ToString(); IReflector r = Reflector.Bind(instance); if (r.ExistProperty(propertyName)) { return(r.GetPropertyValue(propertyName)); } else if (r.ExistField(propertyName)) { return(r.GetFieldValue(propertyName)); } else { ExceptionHelper.ThrowIndexOrPropertyNotExist(instance.GetType(), propertyName); } } //Note:Can not convert to property, throw throw; } } }
public override object Visit(NewNode obj) { ClassDefination cd = (ClassDefination)obj.Type.Accept(this); object[] paramList = (object[])obj.CtorParams.Accept(this); ISmartInvoker s = EvalSmartInvoker.CreateInstance(cd.ObjType, false); return(s.InvokeConstructor(paramList)); }