Esempio n. 1
0
        /// <summary>
        /// Converts the value of this instance to an equivalent string value using the specified culture-specific formatting information.
        /// </summary>
        /// <param name="targetParameter">Target parameter for this conversion.</param>
        /// <returns>A string value equivalent to the value of this instance.  May be null.</returns>
        public override string ToString(IParameter targetParameter)
        {
            if (_value != null && HasEnumeratedState)
            {
                EnumPairCollection enumPairs = targetParameter.EnumPairs;

                string value = (bool)_value ? enumPairs.GetWireValueFromEnumId(CheckedEnumRef) : enumPairs.GetWireValueFromEnumId(UncheckedEnumRef);

                // It is possible for '{NULL}' to be provided as one of the enum wire values, so we have to act accordingly
                return(value != Atdl.NullValue ? value : null);
            }
            else
            {
                return(_value != null?_value.ToString().ToLower() : null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Provides the state of this EnumState in a format ready to be sent over FIX, e.g., "A B C E".
        /// </summary>
        /// <param name="enumPairs">The EnumPairs for this parameter, to provide the mapping from EnumID values.</param>
        /// <returns>A space-separated string containing zero or more EnumPair WireValues.  If no EnumIDs are enabled,
        /// then null is returned.</returns>
        public string ToWireValue(EnumPairCollection enumPairs)
        {
            _log.Debug(m => m("Converting EnumState to WireValue; current state is {0}", ToString()));

            if (enumPairs.Count != _enumStates.Count)
            {
                throw ThrowHelper.New <InvalidOperationException>(ExceptionContext, ErrorMessages.InconsistentEnumPairsListItemsError);
            }

            // Override the values in the states collection if a non-enum value is supplied.  This is used to handle
            // the unique case of the EditableDropDownList_t control.
            if (NonEnumValue != null)
            {
                return(NonEnumValue.Length > 0 ? NonEnumValue : null);
            }

            bool          hasAtLeastOneValue = false;
            StringBuilder sb = new StringBuilder();

            for (int n = 0; n < _enumStates.Length; n++)
            {
                if (_enumStates[n])
                {
                    string value = enumPairs.GetWireValueFromEnumId(_enumIds[n]);

                    // Typically {NULL} will only be used in a mutually exclusive fashion, although nothing enforces this
                    if (value != Atdl.NullValue)
                    {
                        // Only prepend a space after the first entry
                        if (hasAtLeastOneValue)
                        {
                            sb.AppendFormat(" {0}", value);
                        }
                        else
                        {
                            sb.Append(value);

                            hasAtLeastOneValue = true;
                        }
                    }
                }
            }

            _log.Debug(m => m("EnumState as WireValue is {0}", sb.ToString()));

            return(hasAtLeastOneValue ? sb.ToString() : null);
        }