Esempio n. 1
0
    protected bool ValidateMethodArguments(MethodInfo InMethod)
    {
        if (InMethod.ReturnType != typeof(string))
        {
            DebugHelper.Assert(false, "Method Command must return a string.");
            return(false);
        }
        ParameterInfo[] parameters = InMethod.GetParameters();
        if ((parameters != null) && (parameters.Length > 0))
        {
            for (int i = 0; i < parameters.Length; i++)
            {
                ParameterInfo info = parameters[i];
                if (info.IsOut)
                {
                    DebugHelper.Assert(false, string.Format("method command argument can't be out parameter. Method:{0}, Parameter:{1} {2}", InMethod.Name, info.ParameterType.Name, info.Name));
                    return(false);
                }
                if (info.ParameterType.IsByRef)
                {
                    DebugHelper.Assert(false, string.Format("method command argument can't be ref parameter. Method:{0}, Parameter:{1} {2}", InMethod.Name, info.ParameterType.Name, info.Name));
                    return(false);
                }
                IArgumentDescription description = Singleton <ArgumentDescriptionRepository> .instance.GetDescription(info.ParameterType);

                DebugHelper.Assert(description != null);
                if (!description.AcceptAsMethodParameter(info.ParameterType))
                {
                    DebugHelper.Assert(false, string.Format("unsupported argument type for method command. Method:{0}, {1}, {2}", InMethod.Name, info.ParameterType.Name, info.Name));
                    return(false);
                }
            }
        }
        return(true);
    }
Esempio n. 2
0
        protected bool ValidateMethodArguments(MethodInfo InMethod)
        {
            Type ReturnType = InMethod.ReturnType;

            if (ReturnType != typeof(string))
            {
                DebugHelper.Assert(false, "Method Command must return a string.");
                return(false);
            }

            ParameterInfo[] Parameters = InMethod.GetParameters();

            if (Parameters != null && Parameters.Length > 0)
            {
                for (int i = 0; i < Parameters.Length; ++i)
                {
                    ParameterInfo ParameterType = Parameters[i];

                    if (ParameterType.IsOut)
                    {
                        DebugHelper.Assert(false,
                                           string.Format(
                                               "method command argument can't be out parameter. Method:{0}, Parameter:{1} {2}",
                                               InMethod.Name,
                                               ParameterType.ParameterType.Name,
                                               ParameterType.Name)
                                           );

                        return(false);
                    }

                    /*
                     *  if (ParameterType.IsOptional)
                     *  {
                     *      DebugHelper.Assert(false,
                     *          string.Format(
                     *          "method command argument can't be optional. Method:{0}, Parameter:{1} {2}",
                     *          InMethod.Name,
                     *          ParameterType.ParameterType.Name,
                     *          ParameterType.Name
                     *          )
                     *          );
                     *
                     *      return false;
                     *  }
                     */

                    if (ParameterType.ParameterType.IsByRef)
                    {
                        DebugHelper.Assert(false,
                                           string.Format(
                                               "method command argument can't be ref parameter. Method:{0}, Parameter:{1} {2}",
                                               InMethod.Name,
                                               ParameterType.ParameterType.Name,
                                               ParameterType.Name)
                                           );

                        return(false);
                    }

                    IArgumentDescription ArgDescInterface = ArgumentDescriptionRepository.instance.GetDescription(ParameterType.ParameterType);

                    DebugHelper.Assert(ArgDescInterface != null);

                    if (!ArgDescInterface.AcceptAsMethodParameter(ParameterType.ParameterType))
                    {
                        DebugHelper.Assert(false,
                                           string.Format(
                                               "unsupported argument type for method command. Method:{0}, {1}, {2}",
                                               InMethod.Name,
                                               ParameterType.ParameterType.Name,
                                               ParameterType.Name
                                               )
                                           );

                        return(false);
                    }
                }
            }

            return(true);
        }