Exemplo n.º 1
0
        private bool TryMethod(MethodInfo method, string[] parameters, out string result)
        {
            result = "";
            if (method == null)
            {
                return(false);
            }

            // Parameter-Liste der Methode bestimmen
            ParameterInfo[] methodParams = method.GetParameters();
            if (methodParams.Length != parameters.Length)
            {
                return(false);
            }

            List <object> parameterList = new List <object>();

            for (int i = 0; i < methodParams.Length; i++)
            {
                object param = GameConsoleTools.ParseString(
                    methodParams[i].ParameterType,
                    parameters[i],
                    this.owner.Owner.TypeConverterCollection);

                if (param == null)
                {
                    return(false);
                }
                parameterList.Add(param);
            }

            Type senderType = this.owner.SenderType;

            object objectResult = senderType.InvokeMember(this.functionName,
                                                          BindingFlags.InvokeMethod,
                                                          null,
                                                          this.owner.Sender,
                                                          parameterList.ToArray());

            if (objectResult != null)
            {
                result = objectResult.ToString();
            }
            return(true);
        }
Exemplo n.º 2
0
        private string Set(string value)
        {
            // Typ der Klasse bestimmen, der die Property gehört
            Type type = this.owner.SenderType;

            // PropertyInfo holen
            PropertyInfo prop = type.GetProperty(propertyName);

            // Get-Set-Methode holen
            MethodInfo method = prop.GetSetMethod();

            if (method == null)
            {
                return("ERROR: Property is read-only.");
            }

            // Parameter-Liste der Methode bestimmen
            ParameterInfo[] methodParams = method.GetParameters();
            if (methodParams.Length < 1)
            {
                return("ERROR: Invalid property parameters.");
            }

            List <object> parameterList = new List <object>();

            object parameter = GameConsoleTools.ParseString(
                methodParams[0].ParameterType,
                value,
                this.owner.Owner.TypeConverterCollection);

            if (parameter == null)
            {
                return("ERROR: Could not parse set-value.");
            }
            parameterList.Add(parameter);

            type.InvokeMember(
                propertyName,
                BindingFlags.SetProperty,
                null,
                this.owner.Sender,
                parameterList.ToArray());

            return(this.Get());
        }