本文整理汇总了C#中ObservableCollectionEx.UpdateToMatch方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollectionEx.UpdateToMatch方法的具体用法?C# ObservableCollectionEx.UpdateToMatch怎么用?C# ObservableCollectionEx.UpdateToMatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollectionEx
的用法示例。
在下文中一共展示了ObservableCollectionEx.UpdateToMatch方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateToMatchWithANullKeyFuncThrows
public void UpdateToMatchWithANullKeyFuncThrows()
{
var oc = new ObservableCollectionEx<string>();
var toAdd = new List<string>
{
"Existing",
"Items",
"Foo",
"Bar"
};
oc.UpdateToMatch<string>(toAdd, null);
}
示例2: UpdateToMatchUpdatesChangedItems
public void UpdateToMatchUpdatesChangedItems()
{
var oc = new ObservableCollectionEx<CollectionItem>
{
new CollectionItem("First", 1),
new CollectionItem("Second", 2),
new CollectionItem("Third", 3)
};
var toChange = new List<CollectionItem>
{
new CollectionItem("First", 100),
new CollectionItem("Second", 200),
new CollectionItem("Third", 3)
};
Func<CollectionItem, CollectionItem, bool> updateAction = (i1, i2) =>
{
if (i1.Value != i2.Value)
{
i1.Value = i2.Value;
return true;
}
return false;
};
oc.UpdateToMatch(toChange, i => i.Key, updateAction);
oc.Single(i => i.Key == "First").Value.Should().Be(100);
oc.Single(i => i.Key == "Second").Value.Should().Be(200);
oc.Single(i => i.Key == "Third").Value.Should().Be(3);
}
示例3: UpdateToMatchWithANullCollectionThrows
public void UpdateToMatchWithANullCollectionThrows()
{
var oc = new ObservableCollectionEx<string>();
oc.UpdateToMatch(null, s => s);
}
示例4: UpdateToMatchReturnsTrueIfItemsAreRemoved
public void UpdateToMatchReturnsTrueIfItemsAreRemoved()
{
var oc = new ObservableCollectionEx<string>
{
"Existing",
"Items"
};
var toRemove = new List<string>
{
"Items"
};
oc.UpdateToMatch(toRemove, s => s).Should().BeTrue();
}
示例5: UpdateToMatchReturnsTrueIfItemsAreUpdated
public void UpdateToMatchReturnsTrueIfItemsAreUpdated()
{
var oc = new ObservableCollectionEx<CollectionItem>
{
new CollectionItem("First", 1),
new CollectionItem("Second", 2),
new CollectionItem("Third", 3)
};
var toChange = new List<CollectionItem>
{
new CollectionItem("First", 1),
new CollectionItem("Second", 200),
new CollectionItem("Third", 3)
};
Func<CollectionItem, CollectionItem, bool> updateAction = (i1, i2) =>
{
if (i1.Value != i2.Value)
{
i1.Value = i2.Value;
return true;
}
return false;
};
oc.UpdateToMatch(toChange, i => i.Key, updateAction).Should().BeTrue();
}
示例6: UpdateToMatchReturnsTrueIfItemsAreAdded
public void UpdateToMatchReturnsTrueIfItemsAreAdded()
{
var oc = new ObservableCollectionEx<string>
{
"Existing",
"Items"
};
var toAdd = new List<string>
{
"Existing",
"Items",
"Foo",
"Bar"
};
oc.UpdateToMatch(toAdd, s => s).Should().BeTrue();
}
示例7: UpdateToMatchRemovesMissingItems
public void UpdateToMatchRemovesMissingItems()
{
var oc = new ObservableCollectionEx<string>
{
"Existing",
"Items"
};
var toRemove = new List<string>
{
"Items"
};
oc.UpdateToMatch(toRemove, s => s);
oc.Should().ContainInOrder(toRemove);
oc.Should().OnlyContain(s => toRemove.Contains(s));
oc.Count.Should().Be(1);
}
示例8: UpdateToMatchRaisesCollectionChangeOnlyOnceWithResetIfItemsAreUpdated
public void UpdateToMatchRaisesCollectionChangeOnlyOnceWithResetIfItemsAreUpdated()
{
var oc = new ObservableCollectionEx<CollectionItem>
{
new CollectionItem("First", 1),
new CollectionItem("Second", 2),
new CollectionItem("Third", 3)
};
var toChange = new List<CollectionItem>
{
new CollectionItem("First", 1),
new CollectionItem("Second", 200),
new CollectionItem("Third", 3)
};
Func<CollectionItem, CollectionItem, bool> updateAction = (i1, i2) =>
{
if (i1.Value != i2.Value)
{
i1.Value = i2.Value;
return true;
}
return false;
};
var itemCount = 0;
var eventCount = 0;
var action = NotifyCollectionChangedAction.Add;
oc.CollectionChanged += (sender, args) =>
{
++eventCount;
itemCount = oc.Count;
action = args.Action;
};
oc.UpdateToMatch(toChange, i => i.Key, updateAction).Should().BeTrue();
itemCount.Should().Be(3);
eventCount.Should().Be(1);
action.Should().Be(NotifyCollectionChangedAction.Reset);
}
示例9: UpdateToMatchRaisesCollectionChangeOnlyOnceWithResetIfItemsAreRemoved
public void UpdateToMatchRaisesCollectionChangeOnlyOnceWithResetIfItemsAreRemoved()
{
var oc = new ObservableCollectionEx<string>
{
"Existing",
"Items"
};
var toRemove = new List<string>
{
"Items"
};
var itemCount = 0;
var eventCount = 0;
var action = NotifyCollectionChangedAction.Add;
oc.CollectionChanged += (sender, args) =>
{
++eventCount;
itemCount = oc.Count;
action = args.Action;
};
oc.UpdateToMatch(toRemove, s => s);
itemCount.Should().Be(1);
eventCount.Should().Be(1);
action.Should().Be(NotifyCollectionChangedAction.Reset);
}
示例10: UpdateToMatchAddsNewItems
public void UpdateToMatchAddsNewItems()
{
var oc = new ObservableCollectionEx<string>
{
"Existing",
"Items"
};
var toAdd = new List<string>
{
"Existing",
"Items",
"Foo",
"Bar"
};
oc.UpdateToMatch(toAdd, s => s);
oc.Should().ContainInOrder(toAdd);
oc.Should().OnlyContain(s => toAdd.Contains(s));
oc.Count.Should().Be(4);
}