public static string ModeToString(this ChannelModeInfo mode) { string param = string.Empty; if (!string.IsNullOrEmpty(mode.Parameter)) { param = " " + mode.Parameter; } return(string.Format("{0}{1}{2}", (mode.Set) ? "+" : "-", mode.Mode.ToString(), param)); }
/// <summary> /// Parses a given mode and parameter string to generate a channel mode list. /// </summary> /// <param name="modeString">The mode string that contains the mode info.</param> /// <param name="parameterString">The parameter string that is associated with the mode info.</param> /// <returns></returns> public List <ChannelModeInfo> ParseChannelModeString(string modeString, string parameterString) { List <ChannelModeInfo> modeInfos = new List <ChannelModeInfo>(); try { string[] modeArgs = parameterString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); char[] modeInfo = modeString.ToCharArray(); bool set = true; int argIndex = 0; foreach (char mode in modeInfo) { if (mode.Equals('-')) { set = false; } else if (mode.Equals('+')) { set = true; } else { ChannelModeInfo newMode = new ChannelModeInfo(); newMode.Set = set; ChannelMode foundMode; bool validMode = Enum.TryParse(mode.ToString(), false, out foundMode); if (validMode) { newMode.Mode = foundMode; if (modeArgs.GetUpperBound(0) >= argIndex) { switch (newMode.Mode) { case ChannelMode.k: case ChannelMode.l: case ChannelMode.b: case ChannelMode.e: case ChannelMode.I: case ChannelMode.v: case ChannelMode.h: case ChannelMode.o: case ChannelMode.a: case ChannelMode.q: newMode.Parameter = modeArgs[argIndex]; argIndex++; break; default: newMode.Parameter = string.Empty; break; } } else { newMode.Parameter = string.Empty; } modeInfos.Add(newMode); } } } } catch (Exception ex) { ThrowException(ex, "Unable to parse Channel Mode."); } return(modeInfos); }