Skip to content

Commit 0d73858

Browse files
authored
Merge pull request #391 from DataObjects-NET/7.0-nodecollection-add-imp
NodeCollection.Add improvement
2 parents 15bf5c7 + 022b5bc commit 0d73858

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

Orm/Xtensive.Orm/Sql/Model/NodeCollection.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,8 @@ public override void Add(TNode item)
3939
{
4040
base.Add(item);
4141
var name = item.GetNameInternal();
42-
if (!string.IsNullOrEmpty(name)) {
43-
try {
44-
nameIndex.Add(name, item);
45-
}
46-
catch(ArgumentException) {
47-
throw new ArgumentException(string.Format(Strings.ExItemWithNameXAlreadyExists, name));
48-
}
42+
if (!string.IsNullOrEmpty(name) && !nameIndex.TryAdd(name, item)) {
43+
throw new ArgumentException(string.Format(Strings.ExItemWithNameXAlreadyExists, name));
4944
}
5045
}
5146

0 commit comments

Comments
 (0)