本文整理汇总了C#中ImmutableArray.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# ImmutableArray.Remove方法的具体用法?C# ImmutableArray.Remove怎么用?C# ImmutableArray.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImmutableArray
的用法示例。
在下文中一共展示了ImmutableArray.Remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteTodoReducer
public static ImmutableArray<Todo> DeleteTodoReducer(ImmutableArray<Todo> previousState, DeleteTodoAction action)
{
var todoToDelete = previousState.First(todo => todo.Id == action.TodoId);
return previousState.Remove(todoToDelete);
}
示例2: Update
/// <summary>
/// Update the destination database using data from source database using Id column as identification.
/// </summary>
/// <param name="destination">The destination database.</param>
/// <param name="source">The source database.</param>
/// <param name="records">The updated records from destination database.</param>
/// <returns>True if destination database was updated.</returns>
public static bool Update(XDatabase destination, XDatabase source, out ImmutableArray<XRecord>.Builder records)
{
bool isDirty = false;
records = null;
if (source == null || destination == null)
{
return isDirty;
}
// Check the number of source database columns.
if (source.Columns.Length <= 1)
{
return isDirty;
}
// Check for presence of the Id column in the source database.
if (source.Columns[0].Name != destination.IdColumnName)
{
return isDirty;
}
// Check for matching columns length.
if (source.Columns.Length - 1 != destination.Columns.Length)
{
return isDirty;
}
// Check for matching column names.
for (int i = 1; i < source.Columns.Length; i++)
{
if (source.Columns[i].Name != destination.Columns[i - 1].Name)
{
return isDirty;
}
}
// Create updated records builder.
records = destination.Records.ToBuilder();
// Update or remove existing records.
for (int i = 0; i < destination.Records.Length; i++)
{
var record = destination.Records[i];
var result = source.Records.FirstOrDefault(r => r.Id == record.Id);
if (result != null)
{
// Update existing record.
for (int j = 1; j < result.Values.Length; j++)
{
var valuesBuilder = record.Values.ToBuilder();
valuesBuilder[j - 1] = result.Values[j];
record.Values = valuesBuilder.ToImmutable();
}
isDirty = true;
}
else
{
// Remove existing record.
records.Remove(record);
isDirty = true;
}
}
// Add new records.
for (int i = 0; i < source.Records.Length; i++)
{
var record = source.Records[i];
var result = destination.Records.FirstOrDefault(r => r.Id == record.Id);
if (result == null)
{
var r = source.Records[i];
// Use existing columns.
r.Columns = destination.Columns;
// Skip Id column.
r.Values = r.Values.Skip(1).ToImmutableArray();
// Add new record.
records.Add(r);
isDirty = true;
}
}
return isDirty;
}