From 039de58077986988ce4b0d13edd44c7848947ac3 Mon Sep 17 00:00:00 2001 From: Noisrev Date: Mon, 29 Nov 2021 11:26:21 +0800 Subject: [PATCH] Optimize the code --- Noisrev.League.IO.RST/RSTFile.cs | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/Noisrev.League.IO.RST/RSTFile.cs b/Noisrev.League.IO.RST/RSTFile.cs index 42b0388..560413d 100644 --- a/Noisrev.League.IO.RST/RSTFile.cs +++ b/Noisrev.League.IO.RST/RSTFile.cs @@ -151,26 +151,12 @@ private RSTFile() /// RST Version public RSTFile(byte version) : this() { - // Version 2 and 3 - if (version >= 2 && version < 4) - { - // Set the type Complex. - Type = RType.Complex; - } - // Version 4 and 5 - else if (version == 4 || version == 5) - { - // Set the type Simple. - Type = RType.Simple; - } - // Invalid version. - else - { - // An exception is thrown. - throw new ArgumentException($"Invalid Major version {version}. Must be one of 2, 3, 4, 5"); - } + var type = version.GetRType(); + + /* Check the type */ + if (type == null) throw new ArgumentException($"Invalid Major version {version}. Must be one of 2, 3, 4, 5"); - // Set the version. + this.Type = Type; this.Version = version; } @@ -178,7 +164,7 @@ public RSTFile(byte version) : this() /// Read the RST file from the stream. /// /// The input stream. - /// true to leave the stream open after the System.IO.BinaryReader object is disposed; otherwise, false. + /// true to leave the stream open after the object is disposed; otherwise, false. /// /// /// @@ -411,7 +397,7 @@ public bool SetConfig(string conf) /// Using an output stream, write the RST to that stream. /// /// The output stream. - /// true to leave the stream open after the System.IO.BinaryWriter object is disposed; otherwise, false. + /// true to leave the stream open after the object is disposed; otherwise, false. /// /// ///