System.Xml.NameTable.Get C# (CSharp) Method

Get() public method

public Get ( string value ) : string
value string
return string
        public override string Get( string value ) {
            if ( value == null ) {
                throw new ArgumentNullException("value");
            }
            if ( value.Length == 0 ) {
                return string.Empty;
            }

            int len = value.Length + hashCodeRandomizer;
            int hashCode = len;
            // use value.Length to eliminate the rangecheck
            for ( int i = 0; i < value.Length; i++ ) {
                hashCode += ( hashCode << 7 ) ^ value[i];
            }
            // mix it a bit more
            hashCode -= hashCode >> 17; 
            hashCode -= hashCode >> 11; 
            hashCode -= hashCode >> 5;
            
            for ( Entry e = entries[hashCode & mask]; e != null; e = e.next ) {
                if ( e.hashCode == hashCode && e.str.Equals( value ) ) {
                    return e.str;
                }
            }
            return null;
        }

Same methods

NameTable::Get ( char key, int start, int len ) : string

Usage Example

示例#1
0
        /// <summary>
        /// Creates a new AtomizedString object.
        /// </summary>
        /// <param name="str">The string.  May not be null.</param>
        /// <param name="nameTable">The <Typ>NameTable</Typ> that should contain <P>str</P>,
        /// although this is not enforced (see remarks.)</param>
        /// <remarks>
        /// In order for <Typ>AtomizedString</Typ> comparisons to work correctly, the <P>str</P>
        /// parameter must be contained in the <P>nameTable</P>.  For performance reasons, this
        /// is not checked at runtime, except in debug builds where it throws ArgumentException.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// <P>str</P> or <P>nameTable</P> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// (debug build only) <P>nameTable</P> does not contain <P>str</P>.
        /// </exception>
        internal AtomizedString(string str, NameTable nameTable)
        {
            if (str == null) throw new ArgumentNullException("str");
            if (nameTable == null) throw new ArgumentNullException("nameTable");
            m_NameTable = nameTable;
            // although there is no real guarantee that str is in nameTable without
            // specifically checking, it's not worth it to do so (except in debug builds.)
#if DEBUG
            if (null == nameTable.Get(str)) throw new ArgumentException(Resources.WrongNameTable);
#endif
            m_String = str;
        }
All Usage Examples Of System.Xml.NameTable::Get