diff --git a/Orm/Xtensive.Orm/Orm/Model/IndexInfoRef.cs b/Orm/Xtensive.Orm/Orm/Model/IndexInfoRef.cs
index f85b321a5..9af484cd1 100644
--- a/Orm/Xtensive.Orm/Orm/Model/IndexInfoRef.cs
+++ b/Orm/Xtensive.Orm/Orm/Model/IndexInfoRef.cs
@@ -19,21 +19,19 @@ namespace Xtensive.Orm.Model
///
[Serializable]
[DebuggerDisplay("IndexName = {IndexName}, TypeName = {TypeName}")]
- public sealed class IndexInfoRef
+ public readonly struct IndexInfoRef(IndexInfo indexInfo)
{
- private const string ToStringFormat = "Index '{0}' @ {1}";
-
///
/// Name of the index.
///
- public string IndexName { get; private set; }
+ public string IndexName { get; } = indexInfo.Name;
///
/// Name of the reflecting type.
///
- public string TypeName { get; private set; }
+ public string TypeName { get; } = indexInfo.ReflectedType.Name;
- public TupleDescriptor KeyTupleDescriptor { get; private set; }
+ public TupleDescriptor KeyTupleDescriptor { get; } = indexInfo.KeyTupleDescriptor;
///
/// Resolves this instance to object within specified .
@@ -41,49 +39,28 @@ public sealed class IndexInfoRef
/// Domain model.
public IndexInfo Resolve(DomainModel model)
{
- TypeInfo type;
- if (!model.Types.TryGetValue(TypeName, out type))
+ if (!model.Types.TryGetValue(TypeName, out var type))
throw new InvalidOperationException(string.Format(Strings.ExCouldNotResolveXYWithinDomain, "type", TypeName));
- IndexInfo index;
- if (!type.Indexes.TryGetValue(IndexName, out index)) {
- var hierarchy = type.Hierarchy;
- if (hierarchy != null && hierarchy.InheritanceSchema == InheritanceSchema.SingleTable && hierarchy.Root.Indexes.TryGetValue(IndexName, out index))
+ if (!type.Indexes.TryGetValue(IndexName, out var index)) {
+ if (type.Hierarchy is { } hierarchy && hierarchy.InheritanceSchema == InheritanceSchema.SingleTable && hierarchy.Root.Indexes.TryGetValue(IndexName, out index))
return index;
throw new InvalidOperationException(string.Format(Strings.ExCouldNotResolveXYWithinDomain, "index", IndexName));
}
-
return index;
}
///
/// Creates reference for .
///
- public static implicit operator IndexInfoRef (IndexInfo indexInfo)
- {
- return new IndexInfoRef(indexInfo);
- }
+ public static implicit operator IndexInfoRef (IndexInfo indexInfo) => new(indexInfo);
#region Equality members, ==, !=
///
- public bool Equals(IndexInfoRef other)
- {
- if (other is null)
- return false;
- if (ReferenceEquals(this, other))
- return true;
- return
- other.IndexName==IndexName &&
- other.TypeName==TypeName;
- }
+ public bool Equals(IndexInfoRef other) => IndexName == other.IndexName && TypeName == other.TypeName;
///
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(this, obj))
- return true;
- return Equals(obj as IndexInfoRef);
- }
+ public override bool Equals(object obj) => obj is IndexInfo other && Equals(other);
///
public override int GetHashCode() => HashCode.Combine(IndexName, TypeName);
@@ -96,10 +73,7 @@ public override bool Equals(object obj)
///
/// The result of the operator.
///
- public static bool operator ==(IndexInfoRef x, IndexInfoRef y)
- {
- return Equals(x, y);
- }
+ public static bool operator ==(IndexInfoRef x, IndexInfoRef y) => x.Equals(y);
///
/// Implements the operator !=.
@@ -109,31 +83,11 @@ public override bool Equals(object obj)
///
/// The result of the operator.
///
- public static bool operator !=(IndexInfoRef x, IndexInfoRef y)
- {
- return !Equals(x, y);
- }
+ public static bool operator !=(IndexInfoRef x, IndexInfoRef y) => !x.Equals(y);
#endregion
///
- public override string ToString()
- {
- return string.Format(ToStringFormat, IndexName, TypeName);
- }
-
-
- // Constructors
-
- ///
- /// Initializes a new instance of this class.
- ///
- /// object to make reference for.
- public IndexInfoRef(IndexInfo indexInfo)
- {
- IndexName = indexInfo.Name;
- TypeName = indexInfo.ReflectedType.Name;
- KeyTupleDescriptor = indexInfo.KeyTupleDescriptor;
- }
+ public override string ToString() => $"Index '{IndexName}' @ {TypeName}";
}
}