本文整理汇总了C#中ITable.GetIndex方法的典型用法代码示例。如果您正苦于以下问题:C# ITable.GetIndex方法的具体用法?C# ITable.GetIndex怎么用?C# ITable.GetIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITable
的用法示例。
在下文中一共展示了ITable.GetIndex方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsUniqueColumns
private static bool IsUniqueColumns(ITable table, int rindex, string[] cols, bool nullsAllowed)
{
var tableInfo = table.TableInfo;
// 'identical_rows' keeps a tally of the rows that match our added cell.
IList<int> identicalRows = null;
// Resolve the list of column names to column indexes
var colIndexes = tableInfo.IndexOfColumns(cols).ToList();
// If the value being tested for uniqueness contains NULL, we return true
// if nulls are allowed.
if (colIndexes.Select(x => table.GetValue(rindex, x)).Any(x => x.IsNull))
return nullsAllowed;
foreach (var colIndex in colIndexes) {
var value = table.GetValue(rindex, colIndex);
// We are assured of uniqueness if 'identicalRows != null &&
// identicalRows.Count == 0' This is because 'identicalRows' keeps
// a running tally of the rows in the table that contain unique columns
// whose cells match the record being added.
if (identicalRows == null || identicalRows.Count > 0) {
// Ask SelectableScheme to return pointers to row(s) if there is
// already a cell identical to this in the table.
var index = table.GetIndex(colIndex);
var list = index.SelectEqual(value).ToList();
// If 'identical_rows' hasn't been set up yet then set it to 'ivec'
// (the list of rows where there is a cell which is equal to the one
// being added)
// If 'identical_rows' has been set up, then perform an
// 'intersection' operation on the two lists (only keep the numbers
// that are repeated in both lists). Therefore we keep the rows
// that match the row being added.
if (identicalRows == null) {
identicalRows = list;
} else {
list.Sort();
int rowIndex = identicalRows.Count - 1;
while (rowIndex >= 0) {
int val = identicalRows[rowIndex];
int foundIndex = list.BinarySearch(val);
// If we _didn't_ find the index in the array
if (foundIndex < 0 ||
list[foundIndex] != val) {
identicalRows.RemoveAt(rowIndex);
}
--rowIndex;
}
}
}
}
// If there is 1 (the row we added) then we are unique, otherwise we are
// not.
if (identicalRows != null) {
int sz = identicalRows.Count;
if (sz == 1)
return true;
if (sz > 1)
return false;
if (sz == 0)
throw new InvalidOperationException("Assertion failed: We must be able to find the " +
"row we are testing uniqueness against!");
}
return true;
}