Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a string to the schema.
        /// </summary>
        /// <param name="fieldShortName">Parent field short name.</param>
        /// <param name="value">Value the string corresponds to.</param>
        /// <param name="valueString">Human readable string.</param>
        public void AddValueString(string fieldShortName, long value, string valueString)
        {
            TSharkField field = GetField(fieldShortName);

            string key = string.Concat(fieldShortName, "(", value, ")");

            TSharkString existing;

            if (Strings.TryGetValue(key, out existing))
            {
                TSharkStringValue existingStringValue = (TSharkStringValue)existing;
                existingStringValue.Merge(valueString);
            }
            else
            {
                Strings[key] = new TSharkStringValue(field, value, valueString);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a string to the schema.
        /// </summary>
        /// <param name="fieldShortName">Parent field short name.</param>
        /// <param name="value">Value the string corresponds to.</param>
        /// <param name="valueString">Human readable string.</param>
        public void AddValueString(string fieldShortName, long value, string valueString)
        {
            TSharkField field = GetField(fieldShortName);

            string key = string.Concat(fieldShortName, "(", value, ")");

            TSharkString existing;
            if (Strings.TryGetValue(key, out existing))
            {
                TSharkStringValue existingStringValue = (TSharkStringValue)existing;
                existingStringValue.Merge(valueString);
            }
            else
            {
                Strings[key] = new TSharkStringValue(field, value, valueString);
            }
        }