NVelocity.Util.Introspection.Introspector.GetMethod C# (CSharp) Method

GetMethod() public method

Gets the method defined by name and params for the Class c.
public GetMethod ( Type c, String name, Object parameters ) : MethodInfo
c System.Type Class in which the method search is taking place
name String Name of the method being searched for
parameters Object An array of Objects (not Classes) that describe the the parameters
return System.Reflection.MethodInfo
		public override MethodInfo GetMethod(Type c, String name, Object[] parameters)
		{
			/*
			*  just delegate to the base class
			*/

			try
			{
				return base.GetMethod(c, name, parameters);
			}
			catch(AmbiguousException)
			{
				// whoops.  Ambiguous.  Make a nice log message and return null...
				String msg = "Introspection Error : Ambiguous method invocation " + name + "( ";

				for(int i = 0; i < parameters.Length; i++)
				{
					if (i > 0)
						msg = msg + ", ";

					msg = msg + parameters[i].GetType().FullName;
				}

				msg = msg + ") for class " + c;

				rlog.Error(msg);
			}

			return null;
		}

Usage Example

        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");
        }
All Usage Examples Of NVelocity.Util.Introspection.Introspector::GetMethod