コード例 #1
0
 /// <summary>
 /// Checks the current value of the two incongruous flags simultaneously.
 /// If the two flags are detected ​​at the same time the <exception cref="FormatException">FormatException</exception> will be thrown.
 /// </summary>
 /// <param name="current">Current flag of value </param>
 /// <param name="first">the first incongruous flag to detect</param>
 /// <param name="second">the second  incongruous flag to detect</param>
 private static void CheckIncongruousTypeOfValue(DrCmdValueFlags current, DrCmdValueFlags first, DrCmdValueFlags second)
 {
     if (((current & first) == first) & ((current & second) == second))
     {
         throw new FormatException(string.Format(Msg.OPTION_TYPE_HAS_INCONGRUOUS_TYPES, first.ToString(), second.ToString()));
     }
 }
コード例 #2
0
        /// <summary>
        /// Build values flags from string array from attribute <see cref="DrCmdOptionSettings.ValueFlags"/>
        /// If cannot convert string representation to the ValueFlags <exception cref="FormatException">FormatException</exception> will be threw.
        /// </summary>
        /// <param name="ignoreCase">if true ignore case, otherwise regard case</param>
        /// <returns></returns>
        public DrCmdValueFlags GetValueFlags(bool ignoreCase)
        {
            var             flagValue       = GetAttributeValue(DrCmdOptionSettings.ValueFlags, GetDefaultValueFlags().ToString()).GetValueAsStringArray();
            var             flag            = typeof(DrCmdValueFlags);
            DrCmdValueFlags flagValueAsEnum = 0;

            foreach (var item in flagValue)
            {
                try
                {
                    flagValueAsEnum |= (DrCmdValueFlags)Enum.Parse(flag, item, ignoreCase);
                }
                catch (Exception e)
                {
                    throw new FormatException(string.Format(Msg.CANNOT_PARSE_VALUE_AS_FLAG_OF_VALUE, item), e);
                }
            }
            return(flagValueAsEnum);
        }