diff --git a/Orm/Xtensive.Orm/Orm/Model/TypeInfoCollection.cs b/Orm/Xtensive.Orm/Orm/Model/TypeInfoCollection.cs
index 37a5975838..54d1bf2ee4 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 .
@@ -170,7 +165,7 @@ public override bool Contains(TypeInfo item)
/// Finds the type by its full name.
///
/// The full name of the type to find.
- /// Found type, if any;
+ /// Found type, if any;
/// , if there is no type with specified full name.
public TypeInfo Find(string fullName)
{
@@ -183,7 +178,7 @@ public TypeInfo Find(string fullName)
/// Finds the ancestor of the specified .
///
/// The type to search ancestor for.
- /// instance that is ancestor of specified or
+ /// instance that is ancestor of specified or
/// if the ancestor is not found in this collection.
/// When is .
public TypeInfo FindAncestor(TypeInfo item)
@@ -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;
+ }
}
}
@@ -331,14 +320,18 @@ public TypeInfo FindRoot(TypeInfo item)
/// Finds the ancestor of the specified .
///
/// The type to search ancestor for.
- /// instance that is ancestor of specified or
+ /// instance that is ancestor of specified or
/// if the ancestor is not found in this collection.
/// 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
@@ -443,7 +436,7 @@ protected override string GetExceptionMessage(string key)
// Constructors
-
+
///
public TypeInfoCollection(Node owner, string name)
: base(owner, name)