Skip to content

Commit ed35f3a

Browse files
committed
Removed synchronization from OptionInfo and TargetWrapper.
1 parent e2b994e commit ed35f3a

File tree

7 files changed

+41
-66
lines changed

7 files changed

+41
-66
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Command Line Parser Library 1.9.4.119 Beta for CLR.
1+
Command Line Parser Library 1.9.4.121 Beta for CLR.
22
===
33
The Command Line Parser Library offers to CLR applications a clean and concise API for manipulating command line arguments and related tasks defining switches, options and verb commands. It allows you to display an help screen with an high degree of customization and a simple way to report syntax errors to the end user. Everything that is boring and repetitive to be programmed stands up on library shoulders, letting developers concentrate on core logic.
44
__The search for the command line parser for your application is over, with this library you got a solid parsing API constantly updated since 2005.__
@@ -11,6 +11,8 @@ Compatibility:
1111

1212
News:
1313
---
14+
- Removed synchronization from ``OptionInfo`` and ``TargetWrapper`` (parsing should occur in one thread;
15+
if not, synchronization must be provided by developer not by the library).
1416
- Source in Core dir (public types) placed in tree root.
1517
- Project SampleApp renamed to CommandLine.Demo.
1618
- ``SR.string[.cs]`` managed with tools/invariantstr.exe ([Invariant String Tool](https://github.com/gsscoder/invariantstrtool)).

doc/ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2013-01-20 Giacomo Stelluti Scala <gsscoder@gmail.com>
2+
3+
* Removed synchronization from OptionInfo and TargetWrapper: elaboration occurs in
4+
one method call (::ParseArguments) and should not be divided across threads.
5+
If yes, synchronization must be provided by developer not by the library.
6+
* Version incremented to 1.9.4.121 Beta.
7+
18
2013-01-20 Giacomo Stelluti Scala <gsscoder@gmail.com>
29

310
* Source in Core dir (public types) placed in tree root.

doc/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Command Line Parser Library
33
Project Author/Coordinator: Giacomo Stelluti Scala
44
Main Contributor(s): Steven Evans, Kevin Moore, Dan Nemec (nemec), Alexander Fast (mizipzor)
55
--------------------------------------------------------------------------------------------
6-
Version 1.9.4.119 Beta (*1)
6+
Version 1.9.4.121 Beta (*1)
77
Latest Update: 20-01-2013
88

99
Git home:

src/libcmdline/Internal/OptionInfo.Verbs.cs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,24 @@ public bool HasParameterLessCtor
4141
get { return _hasParameterLessCtor; }
4242
set
4343
{
44-
lock (_setValueLock)
45-
{
46-
_hasParameterLessCtor = value;
47-
}
44+
_hasParameterLessCtor = value;
4845
}
4946
}
5047

5148
public object GetValue(object target)
52-
{
53-
lock (_setValueLock)
54-
{
55-
return _property.GetValue(target, null);
56-
}
49+
{
50+
return _property.GetValue(target, null);
5751
}
5852

5953
public void CreateInstance(object target)
6054
{
61-
lock (_setValueLock)
55+
try
6256
{
63-
try
64-
{
65-
_property.SetValue(target, Activator.CreateInstance(_property.PropertyType), null);
66-
}
67-
catch (Exception e)
68-
{
69-
throw new CommandLineParserException("Instance defined for verb command could not be created.", e);
70-
}
57+
_property.SetValue(target, Activator.CreateInstance(_property.PropertyType), null);
58+
}
59+
catch (Exception e)
60+
{
61+
throw new CommandLineParserException("Instance defined for verb command could not be created.", e);
7162
}
7263
}
7364

@@ -95,4 +86,4 @@ public static OptionMap CreateMap(object target,
9586

9687
private bool _hasParameterLessCtor;
9788
}
98-
}
89+
}

src/libcmdline/Internal/OptionInfo.cs

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,8 @@ public bool SetValue(IList<string> values, object options)
112112
{
113113
try
114114
{
115-
lock (_setValueLock)
116-
{
117-
array.SetValue(Convert.ChangeType(values[i], elementType, Thread.CurrentThread.CurrentCulture), i);
115+
array.SetValue(Convert.ChangeType(values[i], elementType, Thread.CurrentThread.CurrentCulture), i);
118116
_property.SetValue(options, array, null);
119-
}
120117
}
121118
catch (FormatException)
122119
{
@@ -132,17 +129,11 @@ private bool SetValueScalar(string value, object options)
132129
{
133130
if (_property.PropertyType.IsEnum)
134131
{
135-
lock (_setValueLock)
136-
{
137-
_property.SetValue(options, Enum.Parse(_property.PropertyType, value, true), null);
138-
}
132+
_property.SetValue(options, Enum.Parse(_property.PropertyType, value, true), null);
139133
}
140134
else
141135
{
142-
lock (_setValueLock)
143-
{
144-
_property.SetValue(options, Convert.ChangeType(value, _property.PropertyType, Thread.CurrentThread.CurrentCulture), null);
145-
}
136+
_property.SetValue(options, Convert.ChangeType(value, _property.PropertyType, Thread.CurrentThread.CurrentCulture), null);
146137
}
147138
}
148139
catch (InvalidCastException) { return false; } // Convert.ChangeType
@@ -157,10 +148,7 @@ private bool SetNullableValue(string value, object options)
157148
var nc = new NullableConverter(_property.PropertyType);
158149
try
159150
{
160-
lock (_setValueLock)
161-
{
162-
_property.SetValue(options, nc.ConvertFromString(null, Thread.CurrentThread.CurrentCulture, value), null);
163-
}
151+
_property.SetValue(options, nc.ConvertFromString(null, Thread.CurrentThread.CurrentCulture, value), null);
164152
}
165153
// the FormatException (thrown by ConvertFromString) is thrown as Exception.InnerException,
166154
// so we've catch directly System.Exception
@@ -173,42 +161,33 @@ private bool SetNullableValue(string value, object options)
173161

174162
public bool SetValue(bool value, object options)
175163
{
176-
lock (_setValueLock)
177-
{
178-
_property.SetValue(options, value, null);
179-
return true;
180-
}
164+
_property.SetValue(options, value, null);
165+
return true;
181166
}
182167

183168
private bool SetValueList(string value, object options)
184169
{
185-
lock (_setValueLock)
170+
_property.SetValue(options, new List<string>(), null);
171+
var fieldRef = (IList<string>)_property.GetValue(options, null);
172+
var values = value.Split(((OptionListAttribute)_attribute).Separator);
173+
for (int i = 0; i < values.Length; i++)
186174
{
187-
_property.SetValue(options, new List<string>(), null);
188-
var fieldRef = (IList<string>)_property.GetValue(options, null);
189-
var values = value.Split(((OptionListAttribute)_attribute).Separator);
190-
for (int i = 0; i < values.Length; i++)
191-
{
192-
fieldRef.Add(values[i]);
193-
}
194-
return true;
175+
fieldRef.Add(values[i]);
195176
}
177+
return true;
196178
}
197179

198180
public void SetDefault(object options)
199181
{
200182
if (_hasDefaultValue)
201183
{
202-
lock (_setValueLock)
184+
try
185+
{
186+
_property.SetValue(options, _defaultValue, null);
187+
}
188+
catch (Exception e)
203189
{
204-
try
205-
{
206-
_property.SetValue(options, _defaultValue, null);
207-
}
208-
catch (Exception e)
209-
{
210-
throw new CommandLineParserException("Bad default value.", e);
211-
}
190+
throw new CommandLineParserException("Bad default value.", e);
212191
}
213192
}
214193
}
@@ -281,6 +260,5 @@ public bool HasBothNames
281260
private readonly string _mutuallyExclusiveSet;
282261
private readonly object _defaultValue;
283262
private readonly bool _hasDefaultValue;
284-
private readonly object _setValueLock = new object();
285263
}
286264
}

src/libcmdline/Internal/TargetWrapper.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ public bool AddValueItemIfAllowed(string item)
5959
{
6060
return false;
6161
}
62-
lock (this)
63-
{
64-
_valueList.Add(item);
65-
}
62+
_valueList.Add(item);
6663
return true;
6764
}
6865

src/libcmdline/Properties/ThisLibrary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static class ThisLibrary
3333
{
3434
public const string Title = "CommandLine.dll";
3535
public const string Copyright = "Copyright (C) 2005 - 2013 Giacomo Stelluti Scala";
36-
public const string Version = "1.9.4.119";
36+
public const string Version = "1.9.4.121";
3737
public const string ReleaseType = "beta";
3838
public const string InformationalVersion = Version;
3939
}

0 commit comments

Comments
 (0)