From 167b3f5f6de181dc6c102ffe4966e70f40a27772 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 31 Jul 2017 16:46:06 +1000 Subject: [PATCH] Prefer case insensitive string comparisons --- .../Bots/Instructions/OtherInstructions.cs | 2 +- MCGalaxy/Commands/Alias.cs | 9 +++-- MCGalaxy/Commands/CPE/CmdCustomColors.cs | 40 +++++++++---------- .../{Permissions => }/CommandExtraPerms.cs | 0 MCGalaxy/Commands/CommandList.cs | 3 +- .../{Permissions => }/CommandPerms.cs | 2 +- MCGalaxy/Commands/Fun/CmdExplode.cs | 2 +- MCGalaxy/Commands/Fun/CmdTntWars.cs | 2 +- MCGalaxy/Commands/Moderation/CmdHide.cs | 2 +- MCGalaxy/Commands/Moderation/CmdReview.cs | 6 ++- MCGalaxy/Commands/Moderation/CmdXJail.cs | 6 +-- MCGalaxy/Commands/Moderation/CmdXban.cs | 6 +-- MCGalaxy/Commands/Scripting/CmdCompload.cs | 14 +++---- .../Commands/World/CmdOverseer.SubCommands.cs | 12 +++--- MCGalaxy/Commands/World/CmdReload.cs | 4 +- MCGalaxy/Commands/World/CmdUnflood.cs | 2 +- MCGalaxy/Commands/World/CmdUnload.cs | 7 ++-- MCGalaxy/CorePlugin/ConnectHandler.cs | 4 +- .../Drawing/BrushFactories/SimpleBrushes.cs | 4 +- MCGalaxy/Games/TntWars/TntWars.cs | 2 +- MCGalaxy/Games/ZombieSurvival/Pillaring.cs | 2 +- MCGalaxy/MCGalaxy_.csproj | 5 +-- MCGalaxy/Player/Player.Handlers.cs | 2 +- MCGalaxy/util/Extensions/TimeExts.cs | 12 +++--- 24 files changed, 72 insertions(+), 78 deletions(-) rename MCGalaxy/Commands/{Permissions => }/CommandExtraPerms.cs (100%) rename MCGalaxy/Commands/{Permissions => }/CommandPerms.cs (96%) diff --git a/MCGalaxy/Bots/Instructions/OtherInstructions.cs b/MCGalaxy/Bots/Instructions/OtherInstructions.cs index fac9e8205..9fcbe1903 100644 --- a/MCGalaxy/Bots/Instructions/OtherInstructions.cs +++ b/MCGalaxy/Bots/Instructions/OtherInstructions.cs @@ -57,7 +57,7 @@ namespace MCGalaxy.Bots { public override bool Execute(PlayerBot bot, InstructionData data) { string script = (string)data.Metadata; if (File.Exists("bots/" + script)) { - Command.all.Find("botset").Use(null, bot.name + " " + script); + Command.all.FindByName("botset").Use(null, bot.name + " " + script); return true; } bot.NextInstruction(); return true; diff --git a/MCGalaxy/Commands/Alias.cs b/MCGalaxy/Commands/Alias.cs index d938e5e26..c0c70149a 100644 --- a/MCGalaxy/Commands/Alias.cs +++ b/MCGalaxy/Commands/Alias.cs @@ -67,20 +67,21 @@ namespace MCGalaxy.Commands { sw.WriteLine("# it is treated as /help me ."); foreach (Alias a in aliases) { - if (a.Prefix == null) + if (a.Prefix == null) { sw.WriteLine(a.Trigger + " : " + a.Target); - else + } else { sw.WriteLine(a.Trigger + " : " + a.Target + " " + a.Prefix); + } } } } public static Alias Find(string cmd) { foreach (Alias alias in aliases) { - if (alias.Trigger == cmd) return alias; + if (alias.Trigger.CaselessEq(cmd)) return alias; } foreach (Alias alias in coreAliases) { - if (alias.Trigger == cmd) return alias; + if (alias.Trigger.CaselessEq(cmd)) return alias; } return null; } diff --git a/MCGalaxy/Commands/CPE/CmdCustomColors.cs b/MCGalaxy/Commands/CPE/CmdCustomColors.cs index f2938b8bd..67c4b165e 100644 --- a/MCGalaxy/Commands/CPE/CmdCustomColors.cs +++ b/MCGalaxy/Commands/CPE/CmdCustomColors.cs @@ -111,30 +111,28 @@ namespace MCGalaxy.Commands.CPE { if (args.Length < 4) { Help(p); return; } char code = ParseColor(p, args[1]); - if (code == '\0') return; + if (code == '\0') return; ColorDesc col = Colors.List[code]; - switch (args[2]) { - case "name": - if (!CheckName(p, args[3])) return; + if (args[2].CaselessEq("name")) { + if (!CheckName(p, args[3])) return; - Player.Message(p, "Set name of {0} to {1}", col.Name, args[3]); - col.Name = args[3];break; - case "fallback": - char fallback; - if (!CheckFallback(p, args[3], code, out fallback)) return; - - Player.Message(p, "Set fallback of {0} to %&S{1}", col.Name, fallback); - col.Fallback = fallback; break; - case "hex": - case "color": - ColorDesc rgb = default(ColorDesc); - if (!CommandParser.GetHex(p, args[3], ref rgb)) return; - - Player.Message(p, "Set hex color of {0} to {1}", col.Name, Utils.Hex(rgb.R, rgb.G, rgb.B)); - col.R = rgb.R; col.G = rgb.G; col.B = rgb.B; break; - default: - Help(p); return; + Player.Message(p, "Set name of {0} to {1}", col.Name, args[3]); + col.Name = args[3]; + } else if (args[2].CaselessEq("fallback")) { + char fallback; + if (!CheckFallback(p, args[3], code, out fallback)) return; + + Player.Message(p, "Set fallback of {0} to %&S{1}", col.Name, fallback); + col.Fallback = fallback; + } else if (args[2].CaselessEq("hex") || args[2].CaselessEq("color")) { + ColorDesc rgb = default(ColorDesc); + if (!CommandParser.GetHex(p, args[3], ref rgb)) return; + + Player.Message(p, "Set hex color of {0} to {1}", col.Name, Utils.Hex(rgb.R, rgb.G, rgb.B)); + col.R = rgb.R; col.G = rgb.G; col.B = rgb.B; + } else { + Help(p); return; } Colors.Update(col); diff --git a/MCGalaxy/Commands/Permissions/CommandExtraPerms.cs b/MCGalaxy/Commands/CommandExtraPerms.cs similarity index 100% rename from MCGalaxy/Commands/Permissions/CommandExtraPerms.cs rename to MCGalaxy/Commands/CommandExtraPerms.cs diff --git a/MCGalaxy/Commands/CommandList.cs b/MCGalaxy/Commands/CommandList.cs index 5d64bdeb0..962be230d 100644 --- a/MCGalaxy/Commands/CommandList.cs +++ b/MCGalaxy/Commands/CommandList.cs @@ -38,9 +38,8 @@ namespace MCGalaxy { /// Finds the command which has the given name or shortcut, or null if not found. public Command Find(string name) { - name = name.ToLower(); foreach (Command cmd in commands) { - if (cmd.name == name || cmd.shortcut == name) return cmd; + if (cmd.name.CaselessEq(name) || cmd.shortcut.CaselessEq(name)) return cmd; } return null; } diff --git a/MCGalaxy/Commands/Permissions/CommandPerms.cs b/MCGalaxy/Commands/CommandPerms.cs similarity index 96% rename from MCGalaxy/Commands/Permissions/CommandPerms.cs rename to MCGalaxy/Commands/CommandPerms.cs index bbf085621..ba12a8e0c 100644 --- a/MCGalaxy/Commands/Permissions/CommandPerms.cs +++ b/MCGalaxy/Commands/CommandPerms.cs @@ -180,7 +180,7 @@ namespace MCGalaxy.Commands { if (File.Exists(Paths.CmdPermsFile)) { string[] lines = File.ReadAllLines(Paths.CmdPermsFile); - if (lines.Length > 0 && lines[0] == "#Version 2") { + if (lines.Length > 0 && lines[0].CaselessEq("#Version 2")) { LoadVersion2(lines); } else { LoadVersion1(lines); diff --git a/MCGalaxy/Commands/Fun/CmdExplode.cs b/MCGalaxy/Commands/Fun/CmdExplode.cs index 8ad0ed96e..6eeef22e9 100644 --- a/MCGalaxy/Commands/Fun/CmdExplode.cs +++ b/MCGalaxy/Commands/Fun/CmdExplode.cs @@ -30,7 +30,7 @@ namespace MCGalaxy.Commands.Fun { if (message.Length == 0) { Help(p); return; } string[] args = message.SplitSpaces(); if (!(args.Length == 1 || args.Length == 3)) { Help(p); return; } - if (message == "me" && p != null) args[0] = p.name; + if (message.CaselessEq("me") && p != null) args[0] = p.name; ushort x, y, z; if (args.Length == 1) { diff --git a/MCGalaxy/Commands/Fun/CmdTntWars.cs b/MCGalaxy/Commands/Fun/CmdTntWars.cs index 5d1d20b94..258db822b 100644 --- a/MCGalaxy/Commands/Fun/CmdTntWars.cs +++ b/MCGalaxy/Commands/Fun/CmdTntWars.cs @@ -391,7 +391,7 @@ namespace MCGalaxy.Commands.Fun { } it.GameStatus = TntWarsGame.TntWarsGameStatus.WaitingForPlayers; - Command.all.Find("restore").Use(null, it.BackupNumber + it.lvl.name); + Command.all.FindByName("restore").Use(null, it.BackupNumber + it.lvl.name); it.RedScore = 0; it.BlueScore = 0; diff --git a/MCGalaxy/Commands/Moderation/CmdHide.cs b/MCGalaxy/Commands/Moderation/CmdHide.cs index baa44fff0..3afe8a38d 100644 --- a/MCGalaxy/Commands/Moderation/CmdHide.cs +++ b/MCGalaxy/Commands/Moderation/CmdHide.cs @@ -33,7 +33,7 @@ namespace MCGalaxy.Commands.Moderation { } public override void Use(Player p, string message) { - if (message == "check") { + if (message.CaselessEq("check")) { string state = p.hidden ? "" : "not "; Player.Message(p, "You are " + state + "currently hidden!"); return; } diff --git a/MCGalaxy/Commands/Moderation/CmdReview.cs b/MCGalaxy/Commands/Moderation/CmdReview.cs index d35138ba7..a199b88d9 100644 --- a/MCGalaxy/Commands/Moderation/CmdReview.cs +++ b/MCGalaxy/Commands/Moderation/CmdReview.cs @@ -114,8 +114,10 @@ namespace MCGalaxy.Commands.Moderation { if (p == null) { Player.Message(p, "Console cannot leave the review queue."); return; } bool inQueue = false; - foreach (string who in Server.reviewlist) - inQueue |= who == p.name; + foreach (string who in Server.reviewlist) { + inQueue |= who.CaselessEq(p.name); + } + if (!inQueue) { Player.Message(p, "You aren't in the review queue so you cannot leave it."); return; } diff --git a/MCGalaxy/Commands/Moderation/CmdXJail.cs b/MCGalaxy/Commands/Moderation/CmdXJail.cs index 04922fcd8..1c39ccf65 100644 --- a/MCGalaxy/Commands/Moderation/CmdXJail.cs +++ b/MCGalaxy/Commands/Moderation/CmdXJail.cs @@ -48,9 +48,9 @@ namespace MCGalaxy.Commands.Moderation { MessageTooHighRank(p, "xjail", false); return; } - Command spawn = Command.all.Find("spawn"); - Command freeze = Command.all.Find("freeze"); - Command mute = Command.all.Find("mute"); + Command spawn = Command.all.FindByName("spawn"); + Command freeze = Command.all.FindByName("freeze"); + Command mute = Command.all.FindByName("mute"); if (!Server.jailed.Contains(who.name)) { if (!who.muted) mute.Use(p, message + " 10000d"); diff --git a/MCGalaxy/Commands/Moderation/CmdXban.cs b/MCGalaxy/Commands/Moderation/CmdXban.cs index 773180e8b..d42087721 100644 --- a/MCGalaxy/Commands/Moderation/CmdXban.cs +++ b/MCGalaxy/Commands/Moderation/CmdXban.cs @@ -35,9 +35,9 @@ namespace MCGalaxy.Commands.Moderation { if (message.Length == 0) { Help(p); return; } string name = message.SplitSpaces()[0]; - Command.all.Find("undoplayer").Use(p, name + " all"); - if (banIP) Command.all.Find("banip").Use(p, "@" + name); - Command.all.Find("kickban").Use(p, message); + Command.all.FindByName("undoplayer").Use(p, name + " all"); + if (banIP) Command.all.FindByName("banip").Use(p, "@" + name); + Command.all.FindByName("kickban").Use(p, message); } public override void Help(Player p) { diff --git a/MCGalaxy/Commands/Scripting/CmdCompload.cs b/MCGalaxy/Commands/Scripting/CmdCompload.cs index 9afa30bd1..8f3f6676a 100644 --- a/MCGalaxy/Commands/Scripting/CmdCompload.cs +++ b/MCGalaxy/Commands/Scripting/CmdCompload.cs @@ -24,17 +24,13 @@ namespace MCGalaxy.Commands.Scripting { public override bool museumUsable { get { return true; } } public override void Use(Player p, string message) { - string[] param = message.SplitSpaces(); + string[] args = message.SplitSpaces(); if (message.Length == 0) { Help(p); return; } - if (param.Length == 1) { - Command.all.Find("compile").Use(p, message); - Command.all.Find("cmdload").Use(p, message); - Command.all.Find("help").Use(p, message); - } else if (param[1].CaselessEq("vb")) { - Command.all.Find("compile").Use(p, message + " vb"); - Command.all.Find("cmdload").Use(p, message + " vb"); - Command.all.Find("help").Use(p, message); + if (args.Length == 1 || args[1].CaselessEq("vb")) { + Command.all.FindByName("compile").Use(p, message); + Command.all.FindByName("cmdload").Use(p, args[0]); + Command.all.FindByName("help").Use(p, args[0]); } else { Help(p); } diff --git a/MCGalaxy/Commands/World/CmdOverseer.SubCommands.cs b/MCGalaxy/Commands/World/CmdOverseer.SubCommands.cs index 1d6f338f8..a98f3e5e2 100644 --- a/MCGalaxy/Commands/World/CmdOverseer.SubCommands.cs +++ b/MCGalaxy/Commands/World/CmdOverseer.SubCommands.cs @@ -97,10 +97,10 @@ namespace MCGalaxy.Commands.World { } else if (cmd == "DELETE" || cmd == "REMOVE") { DeleteMap(p, value); } else if (cmd == "SAVE") { - Command.all.Find("save").Use(p, ""); + Command.all.FindByName("save").Use(p, ""); Player.Message(p, "Map has been saved."); } else if (cmd == "RESTORE") { - Command.all.Find("restore").Use(p, value); + Command.all.FindByName("restore").Use(p, value); } else if (cmd == "RESIZE") { value = p.level.name + " " + value; string[] args = value.SplitSpaces(); @@ -117,15 +117,15 @@ namespace MCGalaxy.Commands.World { Command.all.Find("perbuild").Use(p, rank); } else if (cmd == "TEXTURE") { if (value.Length == 0) { - Command.all.Find("texture").Use(p, "level normal"); + Command.all.FindByName("texture").Use(p, "level normal"); } else { - Command.all.Find("texture").Use(p, "level " + value); + Command.all.FindByName("texture").Use(p, "level " + value); } } else if (cmd == "TEXTUREZIP") { if (value.Length == 0) { - Command.all.Find("texture").Use(p, "levelzip normal"); + Command.all.FindByName("texture").Use(p, "levelzip normal"); } else { - Command.all.Find("texture").Use(p, "levelzip " + value); + Command.all.FindByName("texture").Use(p, "levelzip " + value); } } else { cmd = LevelOptions.Map(cmd.ToLower()); diff --git a/MCGalaxy/Commands/World/CmdReload.cs b/MCGalaxy/Commands/World/CmdReload.cs index 5dcb82c7d..843cbe25e 100644 --- a/MCGalaxy/Commands/World/CmdReload.cs +++ b/MCGalaxy/Commands/World/CmdReload.cs @@ -34,9 +34,9 @@ namespace MCGalaxy.Commands.World { public override void Use(Player p, string message) { if (CheckSuper(p, message, "player or level name")) return; if (message.Length == 0) message = p.name; - string[] parts = message.ToLower().SplitSpaces(); + string[] parts = message.SplitSpaces(); - if (parts[0] == "all") { + if (parts[0].CaselessEq("all")) { if (!ReloadAll(p, parts)) return; } else { Player who = PlayerInfo.FindMatches(p, parts[0]); diff --git a/MCGalaxy/Commands/World/CmdUnflood.cs b/MCGalaxy/Commands/World/CmdUnflood.cs index 40477bf9a..8e5bdc414 100644 --- a/MCGalaxy/Commands/World/CmdUnflood.cs +++ b/MCGalaxy/Commands/World/CmdUnflood.cs @@ -32,7 +32,7 @@ namespace MCGalaxy.Commands.World { int phys = p.level.physics; CmdPhysics.SetPhysics(p.level, 0); - Command cmd = Command.all.Find("replaceall"); + Command cmd = Command.all.FindByName("replaceall"); string args = message.CaselessEq("all") ? "lavafall waterfall lava_fast active_lava active_water " + "active_hot_lava active_cold_water fast_hot_lava magma geyser" : message; diff --git a/MCGalaxy/Commands/World/CmdUnload.cs b/MCGalaxy/Commands/World/CmdUnload.cs index 3225bb4f0..a30d98e46 100644 --- a/MCGalaxy/Commands/World/CmdUnload.cs +++ b/MCGalaxy/Commands/World/CmdUnload.cs @@ -23,14 +23,13 @@ namespace MCGalaxy.Commands.World { public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override void Use(Player p, string message) { - string name = message.ToLower(); if (CheckSuper(p, message, "level name")) return; - if (name.Length == 0) { + if (message.Length == 0) { if (!p.level.Unload()) { Player.Message(p, "You cannot unload this level."); } - } else if (name == "empty") { + } else if (message.CaselessEq("empty")) { Level[] loaded = LevelInfo.Loaded.Items; for (int i = 0; i < loaded.Length; i++) { Level lvl = loaded[i]; @@ -38,7 +37,7 @@ namespace MCGalaxy.Commands.World { lvl.Unload(true); } } else { - Level level = Matcher.FindLevels(p, name); + Level level = Matcher.FindLevels(p, message); if (level == null) return; if (!level.Unload()) { diff --git a/MCGalaxy/CorePlugin/ConnectHandler.cs b/MCGalaxy/CorePlugin/ConnectHandler.cs index ad9ac0363..7a950bdd7 100644 --- a/MCGalaxy/CorePlugin/ConnectHandler.cs +++ b/MCGalaxy/CorePlugin/ConnectHandler.cs @@ -36,10 +36,10 @@ namespace MCGalaxy.Core { } static void CheckReviewList(Player p) { - Command cmd = Command.all.Find("review"); + Command cmd = Command.all.FindByName("review"); LevelPermission perm = CommandExtraPerms.MinPerm("review"); - if (p.group.Permission < perm || !p.group.Commands.Contains(cmd)) return; + if (p.group.Permission < perm || !p.group.CanExecute(cmd)) return; int count = Server.reviewlist.Count; if (count == 0) return; diff --git a/MCGalaxy/Drawing/BrushFactories/SimpleBrushes.cs b/MCGalaxy/Drawing/BrushFactories/SimpleBrushes.cs index a83c68cd7..1f36d28d9 100644 --- a/MCGalaxy/Drawing/BrushFactories/SimpleBrushes.cs +++ b/MCGalaxy/Drawing/BrushFactories/SimpleBrushes.cs @@ -161,8 +161,8 @@ namespace MCGalaxy.Drawing.Brushes { }; public override Brush Construct(BrushArgs args) { - if (args.Message == "random") return new RandomRainbowBrush(); - if (args.Message == "bw") return new BWRainbowBrush(); + if (args.Message.CaselessEq("random")) return new RandomRainbowBrush(); + if (args.Message.CaselessEq("bw")) return new BWRainbowBrush(); return new RainbowBrush(); } } diff --git a/MCGalaxy/Games/TntWars/TntWars.cs b/MCGalaxy/Games/TntWars/TntWars.cs index 6618a0742..227ae2ed8 100644 --- a/MCGalaxy/Games/TntWars/TntWars.cs +++ b/MCGalaxy/Games/TntWars/TntWars.cs @@ -357,7 +357,7 @@ namespace MCGalaxy.Games } } //Reset map - Command.all.Find("restore").Use(null, BackupNumber + " " + lvl.name); + Command.all.FindByName("restore").Use(null, BackupNumber + " " + lvl.name); if (lvl.Config.PhysicsOverload == 2501) { lvl.Config.PhysicsOverload = 1500; diff --git a/MCGalaxy/Games/ZombieSurvival/Pillaring.cs b/MCGalaxy/Games/ZombieSurvival/Pillaring.cs index a52722cc0..24b4d9b05 100644 --- a/MCGalaxy/Games/ZombieSurvival/Pillaring.cs +++ b/MCGalaxy/Games/ZombieSurvival/Pillaring.cs @@ -74,7 +74,7 @@ namespace MCGalaxy.Games.ZS { } else if (p.Game.BlocksStacked == 4) { if (!p.Game.PillarFined) { Chat.MessageOps(" &cWarning: " + p.ColoredName + " %Sis pillaring!"); - Command.all.Find("take").Use(null, p.name + " 10 Auto fine for pillaring"); + Command.all.FindByName("take").Use(null, p.name + " 10 Auto fine for pillaring"); Player.Message(p, " &cThe next time you pillar, you will be &4kicked&c."); } else { ModAction action = new ModAction(p.name, null, ModActionType.Kicked, "Auto kick for pillaring"); diff --git a/MCGalaxy/MCGalaxy_.csproj b/MCGalaxy/MCGalaxy_.csproj index 1ef790f00..2ca47b8e7 100644 --- a/MCGalaxy/MCGalaxy_.csproj +++ b/MCGalaxy/MCGalaxy_.csproj @@ -196,8 +196,10 @@ + + @@ -351,8 +353,6 @@ - - @@ -728,7 +728,6 @@ - diff --git a/MCGalaxy/Player/Player.Handlers.cs b/MCGalaxy/Player/Player.Handlers.cs index a1e94ff16..2a2e44553 100644 --- a/MCGalaxy/Player/Player.Handlers.cs +++ b/MCGalaxy/Player/Player.Handlers.cs @@ -699,7 +699,7 @@ namespace MCGalaxy { if (cmd != "pass") Logger.Log(LogType.CommandUsage, "{0} used /{1} {2}", name, cmd, message); try { //opstats patch (since 5.5.11) - if (Server.Opstats.Contains(cmd) || (cmd == "review" && message.ToLower() == "next" && Server.reviewlist.Count > 0)) { + if (Server.Opstats.Contains(cmd) || (cmd == "review" && message.CaselessEq("next") && Server.reviewlist.Count > 0)) { Database.Backend.AddRow("Opstats", "Time, Name, Cmd, Cmdmsg", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), name, cmd, message); } diff --git a/MCGalaxy/util/Extensions/TimeExts.cs b/MCGalaxy/util/Extensions/TimeExts.cs index b1b1c075b..801476772 100644 --- a/MCGalaxy/util/Extensions/TimeExts.cs +++ b/MCGalaxy/util/Extensions/TimeExts.cs @@ -70,13 +70,13 @@ namespace MCGalaxy { } static long GetTicks(int num, string unit) { - if (unit == "s" || unit == "S") return num * TimeSpan.TicksPerSecond; - if (unit == "m" || unit == "M") return num * TimeSpan.TicksPerMinute; - if (unit == "h" || unit == "H") return num * TimeSpan.TicksPerHour; - if (unit == "d" || unit == "D") return num * TimeSpan.TicksPerDay; - if (unit == "w" || unit == "W") return num * TimeSpan.TicksPerDay * 7; + if (unit.CaselessEq("s")) return num * TimeSpan.TicksPerSecond; + if (unit.CaselessEq("m")) return num * TimeSpan.TicksPerMinute; + if (unit.CaselessEq("h")) return num * TimeSpan.TicksPerHour; + if (unit.CaselessEq("d")) return num * TimeSpan.TicksPerDay; + if (unit.CaselessEq("w")) return num * TimeSpan.TicksPerDay * 7; - if (unit == "ms" || unit == "MS") return num * TimeSpan.TicksPerMillisecond; + if (unit.CaselessEq("ms")) return num * TimeSpan.TicksPerMillisecond; throw new FormatException(unit); }