Ejemplo n.º 1
0
        /// <summary>
        /// Builds a string representation of this BerTag instance.
        /// Useful for debugging.
        /// </summary>
        /// <returns>A string representation of this BerTag instance in
        /// the form "class-number".</returns>
        public override string ToString()
        {
            var value = BerDefinitions.GetShortClassName(Class) + SplitChars[0] + Number.ToString();

            if (IsContainer)
            {
                value += "!C";
            }

            return(value);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Tries to parse a string in the format "class-number" into a BerTag.
        /// "class" is either "C", "U", "A" or "P".
        /// </summary>
        /// <param name="value">The string to parse.</param>
        /// <param name="tag">Receives the parsed tag if successful.</param>
        /// <returns>True if parsing was successful, otherwise false.</returns>
        public static bool TryParse(string value, out BerTag tag)
        {
            var tokens = value.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries);

            if (tokens.Length == 2)
            {
                BerClass tagClass;

                if (BerDefinitions.GetClassFromName(tokens[0], true, out tagClass))
                {
                    uint number;

                    if (uint.TryParse(tokens[1], out number))
                    {
                        tag = new BerTag(tagClass, number);
                        return(true);
                    }
                }
            }

            tag = Zero;
            return(false);
        }