コード例 #1
0
        public ParserValue InvokeConstructor(Type type, ArrayList parameters)
        {
            Type[]          types = ParserValue.GetTypes(parameters);
            ConstructorInfo info  = type.GetConstructor(types);

            if (info == null)
            {
                Fail("Couldn't find suiting constructor for: " + type.FullName);
            }
            object createdInstance = info.Invoke(ParserValue.GetValues(parameters));

            return(new ParserValue(createdInstance, info.ReflectedType));
        }
コード例 #2
0
        public ParserValue Invoke(string name, ParserValue invokeObject, bool invokeConstructor, ArrayList parameters)
        {
            if (!Enabled)
            {
                return(ParserValue.Empty);
            }

            if (invokeConstructor)
            {
                return(InvokeConstructor(invokeObject.Type, parameters));
            }

            BindingFlags bindingFlags;

            if (invokeObject.Value == null)
            {
                bindingFlags = BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod;
            }
            else
            {
                bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod;
            }

            MethodInfo info = invokeObject.Type.GetMethod(name, bindingFlags, null, this.CalcTypes(parameters), null);

            if (info == null)
            {
                Fail("Couldn't find method " + name + " for class " + invokeObject.Type.ToString());
            }
            object result = null;

            try {
                result = info.Invoke(invokeObject.Value, ParserValue.GetValues(parameters));
            } catch (Exception ex) {
                Fail("Error invoking method: " + invokeObject.Type.ToString() + "." + name + Environment.NewLine +
                     ex.InnerException.ToString());
            }
            return(new ParserValue(result, info.ReturnType));
        }