Skip to content

Get rid of unused IChangeNotifier functionality #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions Orm/Xtensive.Orm/Collections/ChangeNotifierEventArgs.cs

This file was deleted.

27 changes: 0 additions & 27 deletions Orm/Xtensive.Orm/Collections/Interfaces/IChangeNotifier.cs

This file was deleted.

50 changes: 0 additions & 50 deletions Orm/Xtensive.Orm/Orm/Model/NodeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ namespace Xtensive.Orm.Model
public class NodeCollection<TNode> : CollectionBaseSlim<TNode>
where TNode: Node
{
[NonSerialized, DebuggerBrowsable(DebuggerBrowsableState.Never)]
private EventHandler<ChangeNotifierEventArgs> itemChangedHandler;

[NonSerialized, DebuggerBrowsable(DebuggerBrowsableState.Never)]
private EventHandler<ChangeNotifierEventArgs> itemChangingHandler;

protected IDictionary<string, TNode> NameIndex;

/// <summary>
Expand Down Expand Up @@ -63,7 +57,6 @@ public override void Add(TNode item)
try {
base.Add(item);
NameIndex.Add(item.Name, item);
TrySubscribe(item);
}
catch (ArgumentException e){
throw new InvalidOperationException(
Expand All @@ -88,7 +81,6 @@ public override void AddRange(IEnumerable<TNode> nodes)
public override bool Remove(TNode item)
{
if (base.Remove(item)) {
TryUnsubscribe(item);
NameIndex.Remove(item.Name);
return true;
}
Expand All @@ -99,9 +91,6 @@ public override bool Remove(TNode item)
public override void Clear()
{
EnsureNotLocked();
foreach(var item in this) {
TryUnsubscribe(item);
}
base.Clear();
NameIndex.Clear();
}
Expand Down Expand Up @@ -163,43 +152,6 @@ protected virtual string GetExceptionMessage(string key)
return string.Format(Strings.ExItemWithKeyXWasNotFound, key);
}

/// <summary>
/// Tries to subscribe the collection on
/// change notifications from the specified item.
/// </summary>
/// <param name="item">The item to try.</param>
protected void TrySubscribe(TNode item)
{
if (item is IChangeNotifier notifier) {
notifier.Changing += itemChangingHandler;
notifier.Changed += itemChangedHandler;
}
}

/// <summary>
/// Tries to unsubscribe the collection from
/// change notifications from the specified item.
/// </summary>
/// <param name="item">The item to try.</param>
protected void TryUnsubscribe(TNode item)
{
if (item is IChangeNotifier notifier) {
notifier.Changing -= itemChangingHandler;
notifier.Changed -= itemChangedHandler;
}
}

protected virtual void OnItemChanging(object sender, ChangeNotifierEventArgs e)
{
NameIndex.Remove(((TNode) sender).Name);
}

protected virtual void OnItemChanged(object sender, ChangeNotifierEventArgs e)
{
var tNode = (TNode)sender;
NameIndex.Add(tNode.Name, tNode);
}

/// <inheritdoc/>
public override void Lock(bool recursive)
{
Expand Down Expand Up @@ -230,8 +182,6 @@ protected NodeCollection(Node owner, string name, Dictionary<string, TNode> name
NameIndex = nameIndex;
Owner = owner;
Name = name;
itemChangingHandler = OnItemChanging;
itemChangedHandler = OnItemChanged;
}

// Type initializer
Expand Down