Removed obsolete function accessor.

This commit is contained in:
Jarl Gullberg 2017-06-20 15:21:18 +02:00
parent b4b5016597
commit f8cc979ed5
No known key found for this signature in database
GPG key ID: 750FF6F6BDA72D23

View file

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