Exemplo n.º 1
0
        //////////////////////////////////////////////

        public virtual ExpressionValue GetValue(
            DynContext EvalContext,
            String Name,
            Boolean SeekForExtenders,
            Boolean SeekForMethods,
            Boolean SeekInContexts)
        {
#if CASE_INSENSITIVE
            Name = Name.ToUpper();
#endif

            DynContext DynLanContext = EvalContext as DynContext;
            if (DynLanContext == null)
            {
                return(null);
            }

            // szukanie extender'a
            if (SeekForExtenders)
            {
                ExpressionExtenderInfo extender = BuildinExtenders.FindByName(Name);
                if (extender != null)
                {
                    return(new ExpressionValue(extender));
                }
            }

            if (SeekInContexts)
            {
                // szukanie zmiennej w lokalnym kontekście
                if (DynLanContext.CurrentState != DynLanContext.GlobalState)
                {
                    // szukanie zmiennej w metodach gdzie została zadeklarowana metoda
                    if (DynLanContext.Stack != null)
                    {
#if !NET20
                        DynLanState currentState = DynLanContext.
                                                   Stack.
                                                   LastOrDefault();
#else
                        DynLanState currentState = Linq2.LastOrDefault(
                            DynLanContext.Stack);
#endif
                        DynLanMethod method = currentState == null ? null :
                                              currentState.Program as DynLanMethod;

                        if (method != null)
                        {
                            for (Int32 i = DynLanContext.Stack.Count - 2; i >= 0; i--)
                            {
                                DynLanState state = DynLanContext.Stack[i];

                                DynLanMethod thisMethod = state.Program as DynLanMethod;
                                DynLanObject thisObject = state.Object;
                                if (thisMethod == null)
                                {
                                    break;
                                }

                                if (thisMethod != null &&
                                    thisMethod.Methods != null &&
                                    thisMethod.Methods.Contains(method))
                                {
                                    if (thisObject != null &&
                                        thisObject.Contains(Name))
                                    {
                                        return(new ExpressionValue(thisObject[Name]));
                                    }
                                }
                                else
                                {
                                    break;
                                }

                                method = thisMethod;
                            }
                        }
                    }

                    if (DynLanContext.CurrentState.Object != null &&
                        DynLanContext.CurrentState.Object.Contains(Name))
                    {
                        return(new ExpressionValue(DynLanContext.CurrentState.Object[Name]));
                    }
                }

                // szukanie zmiennej w globalnym kontekście
                if (DynLanContext.GlobalState.Object != null &&
                    DynLanContext.GlobalState.Object.Contains(Name))
                {
                    return(new ExpressionValue(DynLanContext.GlobalState.Object[Name]));
                }
            }

            // przeniesione na dło aby metody i zmiennej których nazwy pokrywaja sie z globalnymi
            // mobly byc używane
            // szukanie metody
            if (SeekForMethods)
            {
                ExpressionMethodInfo method = BuildinMethods.FindByName(Name);
                if (method != null)
                {
                    return(new ExpressionValue(method));
                }
            }

            /*for (var i = DynLanContext.Stack.IndexOf(DynLanContext.Current); i >= 0; i--)
             * {
             *  DynLanState context = DynLanContext.Stack[i];
             *
             *  if ((context == DynLanContext.Current || context.ContextType == DynLanContextType.GLOBAL) &&
             *      context.Object != null &&
             *      context.Object.Contains(Name))
             *  {
             *      return new ExpressionValue(context.Object[Name]);
             *  }
             * }*/

            // szukanie po globalnych zmiennych

            /*if (DynLanContext.GlobalContext.ContextType == DynLanContextType.GLOBAL)
             * {
             *  if (DynLanContext.GlobalContext.Object.Contains(Name))
             *      return new ExpressionValue(DynLanContext.GlobalContext.Object[Name]);
             * }*/

            return(null);
        }
Exemplo n.º 2
0
        //////////////////////////////////////////////

        public virtual ExpressionValue GetValue(
            PainContext EvalContext,
            String Name,
            Boolean SeekForExtenders,
            Boolean SeekForMethods,
            Boolean SeekInContexts)
        {
            Name = Name.ToUpper();

            PainContext painContext = EvalContext as PainContext;

            if (painContext == null)
            {
                return(null);
            }

            // szukanie extender'a
            if (SeekForExtenders)
            {
                ExpressionExtenderInfo extender = BuildinExtenders.FindByName(Name);
                if (extender != null)
                {
                    return(new ExpressionValue(extender));
                }
            }

            // szukanie metody
            if (SeekForMethods)
            {
                ExpressionMethodInfo method = BuildinMethods.FindByName(Name);
                if (method != null)
                {
                    return(new ExpressionValue(method));
                }
            }

            if (SeekInContexts)
            {
                // szukanie po innych zmiennych
                if (painContext.CurrentState != painContext.GlobalState)
                {
                    if (painContext.CurrentState.Object != null &&
                        painContext.CurrentState.Object.Contains(Name))
                    {
                        return(new ExpressionValue(painContext.CurrentState.Object[Name]));
                    }
                }

                if (painContext.GlobalState.Object != null &&
                    painContext.GlobalState.Object.Contains(Name))
                {
                    return(new ExpressionValue(painContext.GlobalState.Object[Name]));
                }
            }

            /*for (var i = painContext.Stack.IndexOf(painContext.Current); i >= 0; i--)
             * {
             *  PainState context = painContext.Stack[i];
             *
             *  if ((context == painContext.Current || context.ContextType == PainContextType.GLOBAL) &&
             *      context.Object != null &&
             *      context.Object.Contains(Name))
             *  {
             *      return new ExpressionValue(context.Object[Name]);
             *  }
             * }*/

            // szukanie po globalnych zmiennych

            /*if (painContext.GlobalContext.ContextType == PainContextType.GLOBAL)
             * {
             *  if (painContext.GlobalContext.Object.Contains(Name))
             *      return new ExpressionValue(painContext.GlobalContext.Object[Name]);
             * }*/

            return(null);
        }
Exemplo n.º 3
0
        private static ExpressionMethodResult EvaluateInlineMethod(
            Object Object,
            Object Method,
            IList <Object> MethodParameters,
            DynLanContext DynLanContext)
        {
            if (Method is OnpMethodInfo)
            {
                OnpMethodInfo methodInfo = Method as OnpMethodInfo;

                DynamicCallResult callResult = MyReflectionHelper.CallMethod(
                    methodInfo.Obj,
                    methodInfo.MethodName,
                    CorrectParameters(MethodParameters));

                if (callResult != null)
                {
                    return(new ExpressionMethodResult(callResult.Value));
                }
            }
            else if (Method is OnpActionMethodInfo)
            {
                OnpActionMethodInfo methodInfo = Method as OnpActionMethodInfo;

                if (methodInfo != null && methodInfo.Action != null)
                {
                    return(new ExpressionMethodResult(methodInfo.Action(CorrectParameters(MethodParameters))));
                }
            }
            else if (Method is ExpressionMethod)
            {
                ExpressionMethod       onpMethod = Method as ExpressionMethod;
                ExpressionMethodResult result    = null;

                if (Object is EmptyObject)
                {
                    result = onpMethod.
                             CalculateValueDelegate(
                        DynLanContext,
                        CorrectParameters(MethodParameters));
                }
                else
                {
#if !NET20
                    var tmp = new[] { Object }.Union(MethodParameters);
#else
                    var tmp = Linq2.From(new[] { Object }).Union(MethodParameters).ToArray();
#endif
                    result = onpMethod.
                             CalculateValueDelegate(
                        DynLanContext,
                        CorrectParameters(tmp));
                }

                return(result == null ?
                       new ExpressionMethodResult(null) :
                       result);
            }
            else if (Method is ExpressionMethodInfo)
            {
                ExpressionMethodInfo   onpMethodInfo = Method as ExpressionMethodInfo;
                ExpressionMethod       onpMethod     = BuildinMethods.GetByID(onpMethodInfo.ID);
                ExpressionMethodResult result        = null;

                if (onpMethod == null)
                {
                    return(new ExpressionMethodResult(result));
                }

                if (Object is EmptyObject)
                {
                    result = onpMethod.
                             CalculateValueDelegate(
                        DynLanContext,
                        CorrectParameters(MethodParameters));
                }
                else
                {
#if !NET20
                    var tmp = new[] { Object }.Union(MethodParameters);
#else
                    var tmp = Linq2.From(new[] { Object }).Union(MethodParameters).ToArray();
#endif
                    result = onpMethod.
                             CalculateValueDelegate(
                        DynLanContext,
                        CorrectParameters(tmp));
                }

                if (result != null)
                {
                    result.Value = InternalTypeConverter.ToInner(result.Value);
                }

                return(result == null ?
                       new ExpressionMethodResult(null) :
                       result);
            }
            else if (Method is ExpressionExtender)
            {
                ExpressionExtender onpExtender = Method as ExpressionExtender;

                return(new ExpressionMethodResult(
                           onpExtender.
                           CalculateValueDelegate(
                               DynLanContext,
                               Object,
                               MethodParameters)));
            }
            else if (Method is ExpressionExtenderInfo)
            {
                ExpressionExtenderInfo onpExtenderInfo = Method as ExpressionExtenderInfo;
                ExpressionExtender     onpExtender     = BuildinExtenders.GetByID(onpExtenderInfo.ID);

                if (onpExtender == null)
                {
                    return(new ExpressionMethodResult(null));
                }

                return(new ExpressionMethodResult(
                           onpExtender.
                           CalculateValueDelegate(
                               DynLanContext,
                               Object,
                               MethodParameters)));
            }
            else if (Method is Delegate)
            {
#if NETCE
                throw new NotSupportedException("Calling delegates is forbidden on wince2.0!");
#else
                Delegate m = Method as Delegate;

                DynamicCallResult callResult = MyReflectionHelper.CallMethod(
                    m.Target,
                    m.Method,
                    CorrectParameters(MethodParameters));

                if (callResult != null)
                {
                    return(new ExpressionMethodResult(callResult.Value));
                }
#endif
            }

            if (Method == null)
            {
                if (Object == null)
                {
                    throw new DynLanMethodNotFoundException("Cannot find a method to call");
                }
                else
                {
                    throw new DynLanMethodNotFoundException("Cannot find a method to call in object " + Object.GetType().Name + "");
                }
            }
            throw new DynLanUnsupportedMethodTypeException("Unsupported method type " + Method.GetType() + "!");
        }
Exemplo n.º 4
0
        private static ExpressionMethodResult EvaluateInlineMethod(
            Object Object,
            Object Method,
            IList <Object> MethodParameters,
            PainContext PainContext)
        {
            if (Method is OnpMethodInfo)
            {
                OnpMethodInfo methodInfo = Method as OnpMethodInfo;

                DynamicCallResult callResult = MyReflectionHelper.CallMethod(
                    methodInfo.Obj,
                    methodInfo.Name,
                    MethodParameters);

                if (callResult != null)
                {
                    return(new ExpressionMethodResult(callResult.Value));
                }
            }
            else if (Method is ExpressionMethod)
            {
                ExpressionMethod       onpMethod = Method as ExpressionMethod;
                ExpressionMethodResult result    = null;

                if (Object is EmptyObject)
                {
                    result = onpMethod.
                             CalculateValueDelegate(
                        PainContext,
                        MethodParameters);
                }
                else
                {
                    result = onpMethod.
                             CalculateValueDelegate(
                        PainContext,
                        new[] { Object }.Union(MethodParameters).ToArray());
                }

                return(result == null ?
                       new ExpressionMethodResult(null) :
                       result);
            }
            else if (Method is ExpressionMethodInfo)
            {
                ExpressionMethodInfo   onpMethodInfo = Method as ExpressionMethodInfo;
                ExpressionMethod       onpMethod     = BuildinMethods.GetByID(onpMethodInfo.ID);
                ExpressionMethodResult result        = null;

                if (onpMethod == null)
                {
                    return(new ExpressionMethodResult(result));
                }

                if (Object is EmptyObject)
                {
                    result = onpMethod.
                             CalculateValueDelegate(
                        PainContext,
                        MethodParameters);
                }
                else
                {
                    result = onpMethod.
                             CalculateValueDelegate(
                        PainContext,
                        new[] { Object }.Union(MethodParameters).ToArray());
                }

                return(result == null ?
                       new ExpressionMethodResult(null) :
                       result);
            }
            else if (Method is ExpressionExtender)
            {
                ExpressionExtender onpExtender = Method as ExpressionExtender;

                return(new ExpressionMethodResult(
                           onpExtender.
                           CalculateValueDelegate(
                               PainContext,
                               Object,
                               MethodParameters)));
            }
            else if (Method is ExpressionExtenderInfo)
            {
                ExpressionExtenderInfo onpExtenderInfo = Method as ExpressionExtenderInfo;
                ExpressionExtender     onpExtender     = BuildinExtenders.GetByID(onpExtenderInfo.ID);

                if (onpExtender == null)
                {
                    return(new ExpressionMethodResult(null));
                }

                return(new ExpressionMethodResult(
                           onpExtender.
                           CalculateValueDelegate(
                               PainContext,
                               Object,
                               MethodParameters)));
            }

            if (Method == null)
            {
                if (Object == null)
                {
                    throw new PainMethodNotFoundException("Cannot find a method to call");
                }
                else
                {
                    throw new PainMethodNotFoundException("Cannot find a method to call in object " + Object.GetType().Name + "");
                }
            }
            throw new PainUnsupportedMethodTypeException("Unsupported method type " + Method.GetType() + "!");
        }