Example #1
0
        /// <since> 1.5
        /// </since>
        protected internal virtual void Discover(System.Type clazz)
        {
            try
            {
                Method = introspector.GetMethod(clazz, "get_Item", parameters);

                if (Method == null)
                {
                    Method = introspector.GetMethod(clazz, "Get", parameters);
                }
            }

            /**
             * pass through application level runtime exceptions
             */
            catch (System.SystemException e)
            {
                throw e;
            }
            catch (System.Exception e)
            {
                string msg = "Exception while looking for Get('" + parameters[0] + "') method";
                log.Error(msg, e);
                throw new VelocityException(msg, e);
            }
        }
        protected internal virtual void Discover(Type type, String propertyName)
        {
            // this is gross and linear, but it keeps it straightforward.
            try
            {
                propertyUsed = propertyName;
                property     = introspector.GetProperty(type, propertyUsed);
                if (property != null)
                {
                    return;
                }

                // now the convenience, flip the 1st character
                propertyUsed = propertyName.Substring(0, 1).ToUpper() + propertyName.Substring(1);
                property     = introspector.GetProperty(type, propertyUsed);
                if (property != null)
                {
                    return;
                }

                propertyUsed = propertyName.Substring(0, 1).ToLower() + propertyName.Substring(1);
                property     = introspector.GetProperty(type, propertyUsed);
                if (property != null)
                {
                    return;
                }

                // check for a method that takes no arguments
                propertyUsed = propertyName;
                method       = introspector.GetMethod(type, propertyUsed, new Object[0]);
                if (method != null)
                {
                    return;
                }

                // check for a method that takes no arguments, flipping 1st character
                propertyUsed = propertyName.Substring(0, 1).ToUpper() + propertyName.Substring(1);
                method       = introspector.GetMethod(type, propertyUsed, new Object[0]);
                if (method != null)
                {
                    return;
                }

                propertyUsed = propertyName.Substring(0, 1).ToLower() + propertyName.Substring(1);
                method       = introspector.GetMethod(type, propertyUsed, new Object[0]);
                if (method != null)
                {
                    return;
                }
            }
            catch (System.Exception e)
            {
                runtimeLogger.Error(string.Format("PROGRAMMER ERROR : PropertyExector() : {0}", e));
            }
        }
Example #3
0
        public void Test_Evaluate()
        {
            IRuntimeServices rs = RuntimeSingleton.RuntimeServices;
            Introspector i = new Introspector(rs);
            MethodInfo mi = i.GetMethod(typeof(VelocityTest), "Test_Evaluate", null);
            Assert.IsNotNull(mi, "Expected to find VelocityTest.Test_Evaluate");
            Assert.IsTrue(mi.ToString().Equals("Void Test_Evaluate()"), "method not found");

            mi = i.GetMethod(typeof(ExtendedProperties), "GetString", new Object[] {"parm1", "parm2"});
            Assert.IsNotNull(mi, "Expected to find ExtendedProperties.GetString(String, String)");
            Assert.IsTrue(mi.ToString().Equals("System.String GetString(System.String, System.String)"), "method not found");
        }
        public void Test_Evaluate()
        {
            IRuntimeServices rs = RuntimeSingleton.RuntimeServices;
            Introspector     i  = new Introspector(rs);
            MethodInfo       mi = i.GetMethod(typeof(VelocityTest), "Test_Evaluate", null);

            Assert.IsNotNull(mi, "Expected to find VelocityTest.Test_Evaluate");
            Assert.IsTrue(mi.ToString().Equals("Void Test_Evaluate()"), "method not found");

            mi = i.GetMethod(typeof(ExtendedProperties), "GetString", new Object[] { "parm1", "parm2" });
            Assert.IsNotNull(mi, "Expected to find ExtendedProperties.GetString(String, String)");
            Assert.IsTrue(mi.ToString().Equals("System.String GetString(System.String, System.String)"), "method not found");
        }
Example #5
0
 public GetExecutor(IRuntimeLogger r, Introspector i, Type c, string key)
 {
     this.rlog    = r;
     this.args[0] = key;
     this.method  = i.GetMethod(c, "get_Item", this.args);
     if (this.method == null)
     {
         this.method = i.GetMethod(c, "Get", this.args);
         if (this.method == null)
         {
             this.method = i.GetMethod(c, "get", this.args);
         }
     }
 }
Example #6
0
    /// <summary>
    /// Performs the undo.
    /// </summary>
    /// <param name="isUndo">If set to <c>true</c>, undo. Otherwise, redo</param>
    public static void PerformUndo(bool isUndo = true)
    {
        UndoEntry entry;

        if (isUndo)
        {
            if (!hasUndo)
            {
                return;
            }
            entry      = undoList[undoIndex - 1];
            undoIndex -= 1;
        }
        else
        {
            if (!hasRedo)
            {
                return;
            }
            entry      = undoList[undoIndex];
            undoIndex += 1;
        }
        object[] args = { entry, isUndo };
        Introspector.GetMethod(entry.callingObject, "PerformUndo").Invoke(entry.callingObject, args);
    }
Example #7
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.name.Substring(0, 1) != "_")
        {
            Debug.Log("MethodButton should be named _[name of method]");
        }
        object component  = Introspector.GetParent(property);
        string methodName = property.name.Substring(1);
        //var value = Introspector.GetValue(component, property.name.Substring(1));
        //		label = EditorGUI.BeginProperty(position, label, property);
        MethodButton methodButton = (MethodButton)Introspector.GetValue(component, property.name);

        if (methodButton != null)
        {
            label.tooltip = methodButton.tooltip;
        }
        Rect contentPosition = EditorGUI.PrefixLabel(position, label);

        if (GUI.Button(contentPosition, new GUIContent(methodName + "()", label.tooltip)))
        {
            MethodInfo methodInfo = Introspector.GetMethod(component, methodName);
            if (methodInfo != null)
            {
                methodInfo.Invoke(component, null);
            }
        }
    }
Example #8
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public GetExecutor(IRuntimeLogger r, Introspector i, Type c, String key)
        {
            runtimeLogger = r;
            arguments[0]  = key;

            // NOTE: changed from get to get to get_Item - assumption is that get would be converted to an indexer in .Net
            // to keep some resemblance to the Java version, look for "Get" and "get" methods as well (both cases for .Net style and java)
            method = i.GetMethod(c, "get_Item", arguments);
            if (method == null)
            {
                method = i.GetMethod(c, "Get", arguments);
                if (method == null)
                {
                    method = i.GetMethod(c, "get", arguments);
                }
            }
        }
        /// <param name="clazz">
        /// </param>
        /// <param name="arg">
        /// </param>
        protected internal virtual void Discover(System.Type clazz, object arg)
        {
            object[] params_Renamed;

            // If you passed in null as property, we don't use the value
            // for parameter lookup. Instead we just look for Put(Object) without
            // any parameters.
            //
            // In any other case, the following condition will set up an array
            // for looking up Put(String, Object) on the class.

            if (property == null)
            {
                // The passed in arg object is used by the Cache to look up the method.
                params_Renamed = new object[] { arg };
            }
            else
            {
                params_Renamed = new object[] { property, arg };
            }

            try
            {
                Method = introspector.GetMethod(clazz, "Put", params_Renamed);
            }

            /**
             * pass through application level runtime exceptions
             */
            catch (System.SystemException e)
            {
                throw e;
            }
            catch (System.Exception e)
            {
                string msg = "Exception while looking for Put('" + params_Renamed[0] + "') method";
                log.Error(msg, e);
                throw new VelocityException(msg, e);
            }
        }
Example #10
0
        /// <param name="clazz">
        /// </param>
        /// <param name="property">
        /// </param>
        /// <param name="arg">
        /// </param>
        protected internal virtual void Discover(System.Type clazz, string property, object arg)
        {
            object[] parameters = new object[] { arg };

            try
            {
                Method = (introspector.GetMethod(clazz, "set_" + property, parameters));
            }

            /**
             * pass through application level runtime exceptions
             */
            catch (System.SystemException e)
            {
                throw e;
            }
            catch (System.Exception e)
            {
                string msg = "Exception while looking for property setter for '" + property;
                log.Error(msg, e);
                throw new VelocityException(msg, e);
            }
        }