Example #1
0
        //------------------------------------------------------------
        // CNameManager.GetNameID
        //
        /// <summary></summary>
        /// <param name="name"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        virtual internal int GetNameID(string name)
        {
            if (name == null)
            {
                return(0);   // id starts from 1;
            }

            int id = 0;

            if (this.nameDictionary.TryGetValue(name, out id))
            {
                return(id);
            }

            id = CObjectID.GenerateID();
            try
            {
                this.nameDictionary.Add(name, id);
            }
            catch (ArgumentException)
            {
                DebugUtil.Assert(false);
                return(0);
            }
            return(id);
        }
Example #2
0
        // Do not define AddString method. Use Add and AddLen methods.

        //------------------------------------------------------------
        // CNameManager.AddString
        //
        /// <summary>
        /// <para>Register a string to dictionary.</para>
        /// <para>if the name has been already registered, return false.</para>
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        //------------------------------------------------------------
        virtual internal bool AddString(string name)
        {
            if (name == null)
            {
                return(false);
            }

            if (!nameDictionary.ContainsKey(name))
            {
                nameDictionary.Add(name, CObjectID.GenerateID());
                return(true);
            }
            return(false);
        }