diff --git a/Orm/Xtensive.Orm/Orm/Model/TypeInfoCollection.cs b/Orm/Xtensive.Orm/Orm/Model/TypeInfoCollection.cs
index 37a5975838..fc40174f1c 100644
--- a/Orm/Xtensive.Orm/Orm/Model/TypeInfoCollection.cs
+++ b/Orm/Xtensive.Orm/Orm/Model/TypeInfoCollection.cs
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2020 Xtensive LLC.
+// Copyright (C) 2007-2021 Xtensive LLC.
// This code is distributed under MIT license terms.
// See the License.txt file in the project root for more information.
// Created by: Dmitri Maximov
@@ -34,14 +34,9 @@ public sealed class TypeInfoCollection
/// An indexer that provides access to collection items.
///
/// Item was not found.
- public TypeInfo this[Type key] {
- get {
- TypeInfo result;
- if (!TryGetValue(key, out result))
- throw new KeyNotFoundException(string.Format(Strings.TypeXIsNotRegistered, key.GetShortName()));
- return result;
- }
- }
+ public TypeInfo this[Type key] => TryGetValue(key, out var result)
+ ? result
+ : throw new KeyNotFoundException(string.Format(Strings.TypeXIsNotRegistered, key.GetShortName()));
///
/// An indexer that provides access to collection items by their .
@@ -217,15 +212,13 @@ public IEnumerable FindDescendants(TypeInfo item, bool recursive)
{
ArgumentValidator.EnsureArgumentNotNull(item, "item");
- HashSet result;
- if (!descendantTable.TryGetValue(item, out result))
- result = new HashSet();
-
- foreach (var item1 in result) {
- yield return item1;
- if (recursive)
- foreach (var item2 in FindDescendants(item1, true))
- yield return item2;
+ if (descendantTable.TryGetValue(item, out var result)) {
+ foreach (var item1 in result) {
+ yield return item1;
+ if (recursive)
+ foreach (var item2 in FindDescendants(item1, true))
+ yield return item2;
+ }
}
}
@@ -251,12 +244,10 @@ public IEnumerable FindInterfaces(TypeInfo item, bool recursive)
{
ArgumentValidator.EnsureArgumentNotNull(item, "item");
- HashSet result;
- if (!interfaceTable.TryGetValue(item, out result))
- result = new HashSet();
-
- foreach (var item1 in result)
- yield return item1;
+ if (interfaceTable.TryGetValue(item, out var result)) {
+ foreach (var item1 in result)
+ yield return item1;
+ }
if (!recursive || item.IsInterface)
yield break;
@@ -293,15 +284,13 @@ public IEnumerable FindImplementors(TypeInfo item, bool recursive)
{
ArgumentValidator.EnsureArgumentNotNull(item, "item");
- HashSet result;
- if (!implementorTable.TryGetValue(item, out result))
- result = new HashSet();
-
- foreach (var item1 in result) {
- yield return item1;
- if (recursive && !item1.IsInterface)
- foreach (var item2 in FindDescendants(item1, true))
- yield return item2;
+ if (implementorTable.TryGetValue(item, out var result)) {
+ foreach (var item1 in result) {
+ yield return item1;
+ if (recursive && !item1.IsInterface)
+ foreach (var item2 in FindDescendants(item1, true))
+ yield return item2;
+ }
}
}
@@ -336,9 +325,13 @@ public TypeInfo FindRoot(TypeInfo item)
/// When is .
private TypeInfo FindAncestor(Type type)
{
- if (type == WellKnownTypes.Object || type.BaseType == null)
+ if (type == WellKnownTypes.Object) {
return null;
- return Contains(type.BaseType) ? this[type.BaseType] : FindAncestor(type.BaseType);
+ }
+ return type.BaseType switch {
+ null => null,
+ var baseType => TryGetValue(baseType, out var typeInfo) ? typeInfo : FindAncestor(baseType)
+ };
}
#endregion