Exemplo n.º 1
0
        /// <inheritdoc />
        public virtual void Add(string name, int?ordinal, FudgeFieldType type, object value)
        {
            if (ordinal.HasValue && (ordinal < short.MinValue || ordinal > short.MaxValue))
            {
                throw new ArgumentOutOfRangeException("ordinal", "Ordinal must be within signed 16-bit range");
            }
            if (type == null)
            {
                // See if we can derive it
                type = context.TypeHandler.DetermineTypeFromValue(value);
                if (type == null)
                {
                    throw new ArgumentException("Cannot determine a Fudge type for value " + value + " of type " + value.GetType());
                }
            }

            if (type == FudgeMsgFieldType.Instance && !(value is FudgeMsg))
            {
                // Copy the fields across to a new message
                value = CopyContainer((IFudgeFieldContainer)value);
            }

            // Adjust values to the lowest possible representation.
            value = type.Minimize(value, ref type);

            FudgeMsgField field = new FudgeMsgField(type, value, name, (short?)ordinal);

            fields.Add(field);
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public override object Minimize(object value, ref FudgeFieldType type)
        {
            type = wireType;
            object newValue = outputConverter((T)value);

            return(wireType.Minimize(newValue, ref type));       // Allow the wire type to minimise further if it wants
        }