/// <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); }
/// <summary> /// Updates any fields which have an ordinal index only to include a field name if one is available in the taxonomy. The /// same taxonomy is passed to any submessages. /// </summary> /// <param name="taxonomy">taxonomy to set field names from</param> public void SetNamesFromTaxonomy(IFudgeTaxonomy taxonomy) { if (taxonomy == null) { return; } for (int i = 0; i < fields.Count; i++) { FudgeMsgField field = fields[i]; if ((field.Ordinal != null) && (field.Name == null)) { string nameFromTaxonomy = taxonomy.GetFieldName(field.Ordinal.Value); if (nameFromTaxonomy == null) { continue; } FudgeMsgField replacementField = new FudgeMsgField(field.Type, field.Value, nameFromTaxonomy, field.Ordinal); fields[i] = replacementField; } if (field.Value is FudgeMsg) { FudgeMsg subMsg = (FudgeMsg)field.Value; subMsg.SetNamesFromTaxonomy(taxonomy); } } }
/// <summary> /// Helper function for converting to a base interface to satisfy C# type checking rules on collections. Can be used, for /// example, to turn a List<FudgeMsgField> into a List<IFudgeField> using the ConvertAll method on List. /// </summary> /// <param name="f">a FudgeMsgField object</param> /// <returns>a IFudgeField object</returns> public static IFudgeField toIFudgeField(FudgeMsgField f) { return((IFudgeField)f); }
/// <summary> /// Helper function for converting to a base interface to satisfy C# type checking rules on collections. Can be used, for /// example, to turn a List<FudgeMsgField> into a List<IFudgeField> using the ConvertAll method on List. /// </summary> /// <param name="f">a FudgeMsgField object</param> /// <returns>a IFudgeField object</returns> public static IFudgeField ToIFudgeField(FudgeMsgField f) { return (IFudgeField)f; }