fCraft.CommandDescriptor.ToString C# (CSharp) Method

ToString() public method

public ToString ( ) : string
return string
        public override string ToString()
        {
            return String.Format( "CommandDescriptor({0})", Name );
        }

Usage Example

        internal static void RegisterCommand([NotNull] CommandDescriptor descriptor)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException("descriptor");
            }

#if DEBUG
            if (descriptor.Category == CommandCategory.None && !descriptor.IsCustom)
            {
                throw new CommandRegistrationException("Standard commands must have a category set.");
            }
#endif

            if (!IsValidCommandName(descriptor.Name))
            {
                throw new CommandRegistrationException("All commands need a name, between 1 and 16 alphanumeric characters long.");
            }

            string normalizedName = descriptor.Name.ToLower();

            if (Commands.ContainsKey(normalizedName))
            {
                throw new CommandRegistrationException("A command with the name \"{0}\" is already registered.", descriptor.Name);
            }

            if (ReservedCommandNames.Contains(normalizedName))
            {
                throw new CommandRegistrationException("The command name is reserved.");
            }

            if (descriptor.Handler == null)
            {
                throw new CommandRegistrationException("All command descriptors are required to provide a handler callback.");
            }

            if (descriptor.Aliases != null)
            {
                if (descriptor.Aliases.Any(alias => Commands.ContainsKey(alias)))
                {
                    throw new CommandRegistrationException("One of the aliases for \"{0}\" is using the name of an already-defined command.", descriptor.ToString());
                }
            }

            if (!Char.IsUpper(descriptor.Name[0]))
            {
                descriptor.Name = descriptor.Name.UppercaseFirst();
            }

            if (descriptor.Usage == null)
            {
                descriptor.Usage = "/" + descriptor.Name;
            }

            if (RaiseCommandRegisteringEvent(descriptor))
            {
                return;
            }

            if (Aliases.ContainsKey(normalizedName))
            {
                Logger.Log(LogType.Warning,
                           "CommandManager.RegisterCommand: \"{0}\" was defined as an alias for \"{1}\", " +
                           "but has now been replaced by a different command of the same name.",
                           descriptor.Name, Aliases[descriptor.Name]);
                Aliases.Remove(normalizedName);
            }

            if (descriptor.Aliases != null)
            {
                foreach (string alias in descriptor.Aliases)
                {
                    string normalizedAlias = alias.ToLower();
                    if (ReservedCommandNames.Contains(normalizedAlias))
                    {
                        Logger.Log(LogType.Warning,
                                   "CommandManager.RegisterCommand: Alias \"{0}\" for \"{1}\" ignored (reserved name).",
                                   alias, descriptor.Name);
                    }
                    else if (Aliases.ContainsKey(normalizedAlias))
                    {
                        Logger.Log(LogType.Warning,
                                   "CommandManager.RegisterCommand: \"{0}\" was defined as an alias for \"{1}\", " +
                                   "but has been overridden to resolve to \"{2}\" instead.",
                                   alias, Aliases[normalizedAlias], descriptor.Name);
                    }
                    else
                    {
                        Aliases.Add(normalizedAlias, normalizedName);
                    }
                }
            }

            Commands.Add(normalizedName, descriptor);

            RaiseCommandRegisteredEvent(descriptor);
        }