From f8cc979ed58339518c0980bee818dd06ff8d5485 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Tue, 20 Jun 2017 15:21:18 +0200 Subject: [PATCH] Removed obsolete function accessor. --- src/Generator.Converter/Options.cs | 67 ++++++++++++------------------ 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/src/Generator.Converter/Options.cs b/src/Generator.Converter/Options.cs index b22bd87a..bd7ab1bd 100644 --- a/src/Generator.Converter/Options.cs +++ b/src/Generator.Converter/Options.cs @@ -13,10 +13,10 @@ // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: -// +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -37,16 +37,16 @@ // A Getopt::Long-inspired option parsing library for C#. // // NDesk.Options.OptionSet is built upon a key/value table, where the -// key is a option format string and the value is a delegate that is +// key is a option format string and the value is a delegate that is // invoked when the format string is matched. // // Option format strings: -// Regex-like BNF Grammar: +// Regex-like BNF Grammar: // name: .+ // type: [=:] // sep: ( [^{}]+ | '{' .+ '}' )? // aliases: ( name type sep ) ( '|' name type sep )* -// +// // Each '|'-delimited name is an alias for the associated action. If the // format string ends in a '=', it has a required value. If the format // string ends in a ':', it has an optional value. If neither '=' or ':' @@ -92,7 +92,7 @@ // p.Parse (new string[]{"-v", "--v", "/v", "-name=A", "/name", "B", "extra"}); // // The above would parse the argument string array, and would invoke the -// lambda expression three times, setting `verbose' to 3 when complete. +// lambda expression three times, setting `verbose' to 3 when complete. // It would also print out "A" and "B" to standard output. // The returned array would contain the string "extra". // @@ -208,7 +208,7 @@ namespace Mono.Options if (c.Option.OptionValueType == OptionValueType.Required && index >= values.Count) throw new OptionException (string.Format ( - c.OptionSet.MessageLocalizer ("Missing required value for option '{0}'."), c.OptionName), + c.OptionSet.MessageLocalizer ("Missing required value for option '{0}'."), c.OptionName), c.OptionName); } @@ -257,7 +257,7 @@ namespace Mono.Options set {option = value;} } - public string OptionName { + public string OptionName { get {return name;} set {name = value;} } @@ -277,7 +277,7 @@ namespace Mono.Options } public enum OptionValueType { - None, + None, Optional, Required, } @@ -318,7 +318,7 @@ namespace Mono.Options throw new ArgumentException ( string.Format ("Cannot provide maxValueCount of {0} for OptionValueType.None.", maxValueCount), "maxValueCount"); - if (Array.IndexOf (names, "<>") >= 0 && + if (Array.IndexOf (names, "<>") >= 0 && ((names.Length == 1 && this.type != OptionValueType.None) || (names.Length > 1 && this.MaxValueCount > 1))) throw new ArgumentException ( @@ -346,8 +346,8 @@ namespace Mono.Options protected static T Parse (string value, OptionContext c) { Type tt = typeof (T); - bool nullable = tt.IsValueType && tt.IsGenericType && - !tt.IsGenericTypeDefinition && + bool nullable = tt.IsValueType && tt.IsGenericType && + !tt.IsGenericTypeDefinition && tt.GetGenericTypeDefinition () == typeof (Nullable<>); Type targetType = nullable ? tt.GetGenericArguments () [0] : typeof (T); TypeConverter conv = TypeDescriptor.GetConverter (targetType); @@ -386,7 +386,7 @@ namespace Mono.Options names [i] = name.Substring (0, end); if (type == '\0' || type == name [end]) type = name [end]; - else + else throw new ArgumentException ( string.Format ("Conflicting option types: '{0}' vs. '{1}'.", type, name [end]), "prototype"); @@ -529,19 +529,6 @@ namespace Mono.Options throw new InvalidOperationException ("Option has no names!"); } - [Obsolete ("Use KeyedCollection.this[string]")] - protected Option GetOptionForName (string option) - { - if (option == null) - throw new ArgumentNullException ("option"); - try { - return base [option]; - } - catch (KeyNotFoundException) { - return null; - } - } - protected override void InsertItem (int index, Option item) { base.InsertItem (index, item); @@ -616,7 +603,7 @@ namespace Mono.Options { if (action == null) throw new ArgumentNullException ("action"); - Option p = new ActionOption (prototype, description, 1, + Option p = new ActionOption (prototype, description, 1, delegate (OptionValueCollection v) { action (v [0]); }); base.Add (p); return this; @@ -631,7 +618,7 @@ namespace Mono.Options { if (action == null) throw new ArgumentNullException ("action"); - Option p = new ActionOption (prototype, description, 2, + Option p = new ActionOption (prototype, description, 2, delegate (OptionValueCollection v) {action (v [0], v [1]);}); base.Add (p); return this; @@ -705,18 +692,18 @@ namespace Mono.Options OptionContext c = CreateOptionContext (); c.OptionIndex = -1; var def = GetOptionForName ("<>"); - var unprocessed = + var unprocessed = from argument in arguments where ++c.OptionIndex >= 0 && (process || def != null) ? process - ? argument == "--" + ? argument == "--" ? (process = false) : !Parse (argument, c) - ? def != null - ? Unprocessed (null, def, c, argument) + ? def != null + ? Unprocessed (null, def, c, argument) : true : false - : def != null + : def != null ? Unprocessed (null, def, c, argument) : true : true @@ -809,7 +796,7 @@ namespace Mono.Options c.Option.Invoke (c); break; case OptionValueType.Optional: - case OptionValueType.Required: + case OptionValueType.Required: ParseValue (v, c); break; } @@ -828,17 +815,17 @@ namespace Mono.Options private void ParseValue (string option, OptionContext c) { if (option != null) - foreach (string o in c.Option.ValueSeparators != null + foreach (string o in c.Option.ValueSeparators != null ? option.Split (c.Option.ValueSeparators, StringSplitOptions.None) : new string[]{option}) { c.OptionValues.Add (o); } - if (c.OptionValues.Count == c.Option.MaxValueCount || + if (c.OptionValues.Count == c.Option.MaxValueCount || c.Option.OptionValueType == OptionValueType.Optional) c.Option.Invoke (c); else if (c.OptionValues.Count > c.Option.MaxValueCount) { throw new OptionException (localizer (string.Format ( - "Error: Found {0} option values when expecting {1}.", + "Error: Found {0} option values when expecting {1}.", c.OptionValues.Count, c.Option.MaxValueCount)), c.OptionName); } @@ -922,7 +909,7 @@ namespace Mono.Options bool indent = false; string prefix = new string (' ', OptionWidth+2); foreach (string line in GetLines (localizer (GetDescription (p.Description)))) { - if (indent) + if (indent) o.Write (prefix); o.WriteLine (line); indent = true; @@ -947,7 +934,7 @@ namespace Mono.Options Write (o, ref written, names [0]); } - for ( i = GetNextOptionIndex (names, i+1); + for ( i = GetNextOptionIndex (names, i+1); i < names.Length; i = GetNextOptionIndex (names, i+1)) { Write (o, ref written, ", "); Write (o, ref written, names [i].Length == 1 ? "-" : "--"); @@ -960,7 +947,7 @@ namespace Mono.Options Write (o, ref written, localizer ("[")); } Write (o, ref written, localizer ("=" + GetArgumentName (0, p.MaxValueCount, p.Description))); - string sep = p.ValueSeparators != null && p.ValueSeparators.Length > 0 + string sep = p.ValueSeparators != null && p.ValueSeparators.Length > 0 ? p.ValueSeparators [0] : " "; for (int c = 1; c < p.MaxValueCount; ++c) {