Changeset 14987 for lang/csharp
- Timestamp:
- 07/01/08 15:36:49 (5 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/csharp/CommandLineParser/CommandLineParser/CommandLineParser.cs
r14971 r14987 79 79 foreach (String optName in GetOptionNames(pi)) 80 80 _availableOptions.Add(optName, pi); 81 82 if (GetDefaultValue(pi) == null) 81 82 Object defaultValue; 83 if (!GetDefaultValue(pi, out defaultValue)) 83 84 { 84 85 _mandatoryOptions.Add(pi.Name); … … 100 101 continue; 101 102 102 Object defaultValue = GetDefaultValue(pi); 103 String defaultOrRequired = (defaultValue == null ? "(Required)" : "(Default: " + defaultValue.ToString() + ")"); 103 Object defaultValue; 104 Boolean hasDefaultValue = GetDefaultValue(pi, out defaultValue); 105 String defaultOrRequired = (hasDefaultValue ? "(Required)" : "(Default: " + defaultValue.ToString() + ")"); 104 106 String[] optionNames = GetOptionNames(pi); 105 107 String optionName = (DelimiterizeAndToLowerCase ? ToLowerAndDelimiterize(optionNames[0]) : optionNames[0]); … … 225 227 foreach (PropertyInfo pi in _availableOptions.Values) 226 228 { 227 Object value = GetDefaultValue(pi);228 if ( pi != null)229 pi.SetValue(returnValue, value, null);229 Object defaultValue; 230 if (GetDefaultValue(pi, out defaultValue)) 231 pi.SetValue(returnValue, defaultValue, null); 230 232 } 231 233 return returnValue; … … 268 270 } 269 271 270 private static Object GetDefaultValue(MemberInfo memberInfo)272 private static Boolean GetDefaultValue(MemberInfo memberInfo, out Object value) 271 273 { 272 274 Object[] attrs = memberInfo.GetCustomAttributes(typeof(DefaultValueAttribute), true); 273 275 if (attrs.Length == 0) 274 return null; 276 { 277 value = null; 278 return false; 279 } 275 280 276 281 DefaultValueAttribute attr = attrs[0] as DefaultValueAttribute; 277 return attr.Value; 282 value = attr.Value; 283 return true; 278 284 } 279 285
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)