/// <summary> /// Since LinkDataView does not support multiple selectors/comparers, it does not make sense for /// them to Find using multiple keys. /// This overriden method prevents users calling multi-key find on dataview. /// </summary> internal override int FindByKey(object[] key) { // must have string or expression based sort specified if (base.SortComparison == null && String.IsNullOrEmpty(base.Sort)) { // This is the exception message from DataView that we want to use throw ExceptionBuilder.IndexKeyLength(0, 0); } else if (base.SortComparison != null && key.Length != sortExpressionBuilder.Count) { throw DataSetUtil.InvalidOperation(SR.Format(SR.LDV_InvalidNumOfKeys, sortExpressionBuilder.Count)); } if (base.SortComparison == null) { // using string to sort return(base.FindByKey(key)); } else { Index.ComparisonBySelector <object, DataRow> compareDelg = new Index.ComparisonBySelector <object, DataRow>(comparerKeyRow); List <object> keyList = new List <object>(); foreach (object singleKey in key) { keyList.Add(singleKey); } Range range = FindRecords <object, DataRow>(compareDelg, keyList); return((range.Count == 0) ? -1 : range.Min); } }
/// <summary> /// Searches the index and finds a single row where the sort-key matches the input key /// </summary> /// <param name="key">Value of the key to find</param> /// <returns>Index of the first match of input key</returns> internal override int FindByKey(object key) { Debug.Assert(base.Sort != null); Debug.Assert(!(!String.IsNullOrEmpty(base.Sort) && base.SortComparison != null), "string and expression based sort cannot both be set"); if (!String.IsNullOrEmpty(base.Sort)) // use find for DV's sort string { return(base.FindByKey(key)); } else if (base.SortComparison == null) // neither string or expr set { // This is the exception message from DataView that we want to use throw ExceptionBuilder.IndexKeyLength(0, 0); } else // find for expression based sort { if (sortExpressionBuilder.Count != 1) { throw DataSetUtil.InvalidOperation(SR.Format(SR.LDV_InvalidNumOfKeys, sortExpressionBuilder.Count)); } Index.ComparisonBySelector <object, DataRow> compareDelg = new Index.ComparisonBySelector <object, DataRow>(comparerKeyRow); List <object> keyList = new List <object>(); keyList.Add(key); Range range = FindRecords <object, DataRow>(compareDelg, keyList); return((range.Count == 0) ? -1 : range.Min); } }
/// <summary> /// Searches the index and finds a single row where the sort-key matches the input key /// </summary> /// <param name="key">Value of the key to find</param> /// <returns>Index of the first match of input key</returns> internal override int FindByKey(object key) { /////////////// Preconditions //////////////// //check that both string and expression based sort are never simultaneously set Debug.Assert(base.Sort != null); Debug.Assert(!(!String.IsNullOrEmpty(base.Sort) && base.SortComparison != null)); ///////////////////////////////////////////// if (!String.IsNullOrEmpty(base.Sort)) //use find for DV's sort string { return base.FindByKey(key); } else if (base.SortComparison == null) //neither string or expr set { //This is the exception message from DataView that we want to use throw ExceptionBuilder.IndexKeyLength(0, 0); } else //find for expression based sort { if (sortExpressionBuilder.Count !=1) throw DataSetUtil.InvalidOperation(Strings.LDV_InvalidNumOfKeys(sortExpressionBuilder.Count)); Index.ComparisonBySelector<object, DataRow> compareDelg = new Index.ComparisonBySelector<object, DataRow>(comparerKeyRow); List<object> keyList = new List<object>(); keyList.Add(key); Range range = FindRecords<object, DataRow>(compareDelg, keyList); return (range.Count == 0) ? -1 : range.Min; } }
/// <summary> /// Since LinkDataView does not support multiple selectors/comparers, it does not make sense for /// them to Find using multiple keys. /// This overriden method prevents users calling multi-key find on dataview. /// </summary> internal override int FindByKey(object[] key) { //---------Checks ---------------- //must have string or expression based sort specified if (base.SortComparison == null && String.IsNullOrEmpty(base.Sort)) { //This is the exception message from DataView that we want to use throw ExceptionBuilder.IndexKeyLength(0, 0); } else if (base.SortComparison != null && key.Length != sortExpressionBuilder.Count) { throw DataSetUtil.InvalidOperation(Strings.LDV_InvalidNumOfKeys(sortExpressionBuilder.Count)); } //-------------------------------- if (base.SortComparison == null)//using string to sort return base.FindByKey(key); else { Index.ComparisonBySelector<object, DataRow> compareDelg = new Index.ComparisonBySelector<object, DataRow>(comparerKeyRow); List<object> keyList = new List<object>(); foreach (object singleKey in key) { keyList.Add(singleKey); } Range range = FindRecords<object, DataRow>(compareDelg, keyList); return (range.Count == 0) ? -1 : range.Min; } }
/// <summary>This method exists for LinqDataView to keep a level of abstraction away from the RBTree</summary> internal Range FindRecords <TKey, TRow>(Index.ComparisonBySelector <TKey, TRow> comparison, TKey key) where TRow : DataRow { return(_index.FindRecords(comparison, key)); }