Changeset 14987 for lang/csharp

Show
Ignore:
Timestamp:
07/01/08 15:36:49 (5 months ago)
Author:
mayuki
Message:

DefaultValue?(null)の時に正しく設定できなかったのを修正した。

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/csharp/CommandLineParser/CommandLineParser/CommandLineParser.cs

    r14971 r14987  
    7979                foreach (String optName in GetOptionNames(pi)) 
    8080                    _availableOptions.Add(optName, pi); 
    81                  
    82                 if (GetDefaultValue(pi) == null) 
     81 
     82                Object defaultValue; 
     83                if (!GetDefaultValue(pi, out defaultValue)) 
    8384                { 
    8485                    _mandatoryOptions.Add(pi.Name); 
     
    100101                    continue; 
    101102 
    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() + ")"); 
    104106                String[] optionNames = GetOptionNames(pi); 
    105107                String optionName = (DelimiterizeAndToLowerCase ? ToLowerAndDelimiterize(optionNames[0]) : optionNames[0]); 
     
    225227            foreach (PropertyInfo pi in _availableOptions.Values) 
    226228            { 
    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); 
    230232            } 
    231233            return returnValue; 
     
    268270        } 
    269271 
    270         private static Object GetDefaultValue(MemberInfo memberInfo) 
     272        private static Boolean GetDefaultValue(MemberInfo memberInfo, out Object value) 
    271273        { 
    272274            Object[] attrs = memberInfo.GetCustomAttributes(typeof(DefaultValueAttribute), true); 
    273275            if (attrs.Length == 0) 
    274                 return null; 
     276            { 
     277                value = null; 
     278                return false; 
     279            } 
    275280 
    276281            DefaultValueAttribute attr = attrs[0] as DefaultValueAttribute; 
    277             return attr.Value; 
     282            value = attr.Value; 
     283            return true; 
    278284        } 
    279285