/// <summary> /// Create object of option by specified node with settings of option /// </summary> /// <param name="command">reference to parent command</param> /// <param name="option">node with settings of option</param> internal DrCmdOption(DrCmdCommand command, DDNode option) { option.Type.ThrowIsNotExpectedNodeType(DrCmdConst.TypeOption); Option = option; Command = command; name = GetOptionName(); type = GetOptionType(); valueType = GetValueType(); }
/// <summary> /// Build options flag from string array from attribute <see cref="DrCmdOptionSettings.Type"/>. /// If cannot convert string representation to the OptionType <exception cref="FormatException">FormatException</exception> will be thrown. /// </summary> /// <param name="ignoreCase">if true ignore case, otherwise regard case</param> /// <returns></returns> public DrCmdOptionType GetOptionType(bool ignoreCase) { var typeOption = GetAttributeValue(DrCmdOptionSettings.Type, GetDefaultOptionType().ToString()).GetValueAsStringArray(); var type = typeof(DrCmdOptionType); DrCmdOptionType typeOptionAsEnum = 0; foreach (var item in typeOption) { try { typeOptionAsEnum |= (DrCmdOptionType)Enum.Parse(type, item, ignoreCase); } catch (Exception e) { throw new FormatException(string.Format(Msg.CANNOT_PARSE_VALUE_AS_TYPE_OF_OPTION, item), e); } } return(typeOptionAsEnum); }