Ejemplo n.º 1
0
        // Private interface
        private bool Parse_Parameters( CSlashCommandInstance command_request, CSlashCommand command, ref string error_string )
        {
            CSlashCommandInfo command_info = Get_Command_Info( command.GetType() );
            if ( !command_request.Parse( command_info.CommandParser, command_info.RequiredParamCount, command_info.RequiredParamCount + command_info.OptionalParamCount ) )
            {
                error_string =	CCommonResource.Get_Text( ECommonTextID.Unable_To_Parse_Slash_Command );
                return false;
            }

            int current_parsed_param = 0;
            foreach ( var param_info in command_info.Params )
            {
                if ( current_parsed_param >= command_request.Count )
                {
                    if ( current_parsed_param < command_info.RequiredParamCount )
                    {
                        error_string =	CCommonResource.Get_Text( ECommonTextID.Slash_Command_Missing_Parameter );
                        return false;
                    }

                    break;
                }

                string param_string_value = command_request[ current_parsed_param ];
                PropertyInfo prop_info = param_info.ParamInfo;

                object param_value = Parse_Parameter( prop_info, param_string_value );
                if ( param_value == null )
                {
                    error_string = string.Format( CCommonResource.Get_Text( ECommonTextID.Unable_To_Parse_Parameter ),
                                                            param_string_value,
                                                            prop_info.Name,
                                                            current_parsed_param,
                                                            prop_info.PropertyType.Name,
                                                            command.GetType().Name );
                    return false;
                }

                prop_info.SetValue( command, param_value, null );
                current_parsed_param++;
            }

            return true;
        }
Ejemplo n.º 2
0
        public bool Try_Parse( CSlashCommandInstance command_request, out CSlashCommand command, out string error_string )
        {
            command = null;
            error_string = "";

            string command_name = command_request.Command;
            if ( command_name == null )
            {
                return false;
            }

            command_name = command_name.ToUpper();

            Type matched_type = Find_Matching_Type( command_name, ref error_string );
            if ( matched_type == null )
            {
                return false;
            }

            CSlashCommand command_instance = Activator.CreateInstance( matched_type ) as CSlashCommand;
            command_instance.On_Command_Name( command_name );

            if ( !Parse_Parameters( command_request, command_instance, ref error_string ) )
            {
                return false;
            }

            command = command_instance;
            return true;
        }