Exemple #1
0
        /// <summary>
        /// Gets the index at which the value should be stored for the specified name,
        /// the method is only used in the case-insensitive case.
        /// </summary>
        /// <param name="name">the name of the member</param>
        /// <param name="obj">The ExpandoObject associated with the class
        /// that is used to check if a member has been deleted.</param>
        /// <returns>
        /// the exact match if there is one
        /// if there is exactly one member with case insensitive match, return it
        /// otherwise we throw AmbiguousMatchException.
        /// </returns>
        private int GetValueIndexCaseInsensitive(string name, ExpandoObject obj)
        {
            int caseInsensitiveMatch = ExpandoObject.NoMatch; //the location of the case-insensitive matching member

            lock (obj.LockObject) {
                for (int i = _keys.Length - 1; i >= 0; i--)
                {
                    if (string.Equals(
                            _keys[i],
                            name,
                            StringComparison.OrdinalIgnoreCase))
                    {
                        //if the matching member is deleted, continue searching
                        if (!obj.IsDeletedMember(i))
                        {
                            if (caseInsensitiveMatch == ExpandoObject.NoMatch)
                            {
                                caseInsensitiveMatch = i;
                            }
                            else
                            {
                                //Ambigous match, stop searching
                                return(ExpandoObject.AmbiguousMatchFound);
                            }
                        }
                    }
                }
            }
            //There is exactly one member with case insensitive match.
            return(caseInsensitiveMatch);
        }
 private int GetValueIndexCaseInsensitive(string name, ExpandoObject obj)
 {
     int num = -1;
     lock (obj.LockObject)
     {
         for (int i = this._keys.Length - 1; i >= 0; i--)
         {
             if (string.Equals(this._keys[i], name, StringComparison.OrdinalIgnoreCase) && !obj.IsDeletedMember(i))
             {
                 if (num != -1)
                 {
                     return -2;
                 }
                 num = i;
             }
         }
     }
     return num;
 }
Exemple #3
0
        private int GetValueIndexCaseInsensitive(string name, ExpandoObject obj)
        {
            int num = -1;

            lock (obj.LockObject)
            {
                for (int i = this._keys.Length - 1; i >= 0; i--)
                {
                    if (string.Equals(this._keys[i], name, StringComparison.OrdinalIgnoreCase) && !obj.IsDeletedMember(i))
                    {
                        if (num != -1)
                        {
                            return(-2);
                        }
                        num = i;
                    }
                }
            }
            return(num);
        }
Exemple #4
0
 /// <summary>
 /// Gets the index at which the value should be stored for the specified name,
 /// the method is only used in the case-insensitive case.
 /// </summary>
 /// <param name="name">the name of the member</param>
 /// <param name="obj">The ExpandoObject associated with the class
 /// that is used to check if a member has been deleted.</param>
 /// <returns>
 /// the exact match if there is one
 /// if there is exactly one member with case insensitive match, return it
 /// otherwise we throw AmbiguousMatchException.
 /// </returns>
 private int GetValueIndexCaseInsensitive(string name, ExpandoObject obj)
 {
     int caseInsensitiveMatch = ExpandoObject.NoMatch; //the location of the case-insensitive matching member
     lock (obj.LockObject)
     {
         for (int i = _keys.Length - 1; i >= 0; i--)
         {
             if (string.Equals(
                 _keys[i],
                 name,
                 StringComparison.OrdinalIgnoreCase))
             {
                 //if the matching member is deleted, continue searching
                 if (!obj.IsDeletedMember(i))
                 {
                     if (caseInsensitiveMatch == ExpandoObject.NoMatch)
                     {
                         caseInsensitiveMatch = i;
                     }
                     else
                     {
                         //Ambiguous match, stop searching
                         return ExpandoObject.AmbiguousMatchFound;
                     }
                 }
             }
         }
     }
     //There is exactly one member with case insensitive match.
     return caseInsensitiveMatch;
 }
Exemple #5
0
 /// <summary>
 /// Gets the index at which the value should be stored for the specified name,
 /// the method is only used in the case-insensitive case.
 /// </summary>
 /// <param name="name">the name of the member</param>
 /// <param name="obj">The ExpandoObject associated with the class
 /// that is used to check if a member has been deleted.</param>
 /// <returns>
 /// the exact match if there is one
 /// if there is exactly one member with case insensitive match, return it
 /// otherwise we throw AmbiguousMatchException.
 /// </returns>
 private int GetValueIndexCaseInsensitive(string name, ExpandoObject obj) {
     int caseInsensitiveMatch = ExpandoObject.NoMatch; //the location of the case-insensitive matching member
     int exactMatch = ExpandoObject.NoMatch;
     bool hasAmbigousMatch = false;
     bool isMatch = false;
     lock (obj.LockObject) {
         for (int i = _keys.Length - 1; i >= 0; i--) {
             if (!hasAmbigousMatch) {
                 //Do case insensitive search if we are not sure if there are ambigous matches
                 if (string.Equals(
                     _keys[i],
                     name,
                     StringComparison.OrdinalIgnoreCase)) {
                     //if the matching member is deleted, continue searching
                     if (!obj.IsDeletedMember(i)) {
                         if (caseInsensitiveMatch == ExpandoObject.NoMatch) {
                             caseInsensitiveMatch = i;
                         } else {
                             hasAmbigousMatch = true;
                         }
                     }
                     isMatch = true;
                 } else {
                     isMatch = false;
                 }
             }
             //Try searching for exact match if we got a match already and haven't got an exact match.
             if (isMatch && caseInsensitiveMatch != ExpandoObject.NoMatch && exactMatch == ExpandoObject.NoMatch) {
                 if (string.Equals(
                     _keys[i],
                     name,
                     StringComparison.Ordinal)) {
                     if (obj.IsDeletedMember(i)) {
                         //We know there is an exact match but it is deleted.
                         //No need to look for exact match after this.
                         exactMatch = i;
                     } else {
                         //the exact match has the highest priority
                         return i;
                     }
                 }
             }
         }
     }
     //if there is an available exact match, it should have been returned.
     if (hasAmbigousMatch) {
         return ExpandoObject.AmbiguousMatchFound;
     }
     //There is exactly one member with case insensitive match.
     return caseInsensitiveMatch;
 }