/// <summary> /// Finds a registered string that corresponds to the given field value. /// </summary> /// <param name="value">Field value.</param> /// <returns>Corresponding string, or null if none.</returns> public string FindString(object value) { if (Strings.Count == 0 || value == null) { return(null); } if (value is bool) { bool boolValue = (bool)value; foreach (TSharkString s in Strings) { TSharkStringTrueFalse tfs = s as TSharkStringTrueFalse; if (tfs != null) { if (boolValue) { return(tfs.TrueStringValue); } else { return(tfs.FalseStringValue); } } } } else { long longValue; if (!long.TryParse(Convert.ToString(value), out longValue)) { return(null); } foreach (TSharkString s in Strings) { TSharkStringRange rs = s as TSharkStringRange; if (rs != null) { if (longValue >= rs.LowerBound && longValue <= rs.UpperBound) { return(rs.StringValue); } } else { TSharkStringValue vs = s as TSharkStringValue; if (vs != null) { if (vs.Value == longValue) { return(vs.StringValue); } } } } } return(null); }
/// <summary> /// Adds a string to the schema. /// </summary> /// <param name="fieldShortName">Parent field short name.</param> /// <param name="lowerBound">Lower bound for values the string corresponds to.</param> /// <param name="upperBound">Upper bound for values the string corresponds to.</param> /// <param name="rangeString">Human readable string.</param> public void AddRangeString(string fieldShortName, long lowerBound, long upperBound, string rangeString) { TSharkField field = GetField(fieldShortName); string key = string.Concat(fieldShortName, "(", lowerBound, "-", upperBound, ")"); TSharkString existing; if (Strings.TryGetValue(key, out existing)) { TSharkStringRange existingStringRange = (TSharkStringRange)existing; existingStringRange.Merge(rangeString); } else { Strings[key] = new TSharkStringRange(field, lowerBound, upperBound, rangeString); } }
/// <summary> /// Adds a string to the schema. /// </summary> /// <param name="fieldShortName">Parent field short name.</param> /// <param name="lowerBound">Lower bound for values the string corresponds to.</param> /// <param name="upperBound">Upper bound for values the string corresponds to.</param> /// <param name="rangeString">Human readable string.</param> public void AddRangeString(string fieldShortName, long lowerBound, long upperBound, string rangeString) { TSharkField field = GetField(fieldShortName); string key = string.Concat(fieldShortName, "(", lowerBound, "-", upperBound, ")"); TSharkString existing; if (Strings.TryGetValue(key, out existing)) { TSharkStringRange existingStringRange = (TSharkStringRange)existing; existingStringRange.Merge(rangeString); } else { Strings[key] = new TSharkStringRange(field, lowerBound, upperBound, rangeString); } }