Skip to content

Commit b6ae044

Browse files
authored
Make IndexInfoRef readonly struct (#267)
1 parent 71b9e44 commit b6ae044

File tree

1 file changed

+13
-59
lines changed

1 file changed

+13
-59
lines changed

Orm/Xtensive.Orm/Orm/Model/IndexInfoRef.cs

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,71 +19,48 @@ namespace Xtensive.Orm.Model
1919
/// </summary>
2020
[Serializable]
2121
[DebuggerDisplay("IndexName = {IndexName}, TypeName = {TypeName}")]
22-
public sealed class IndexInfoRef
22+
public readonly struct IndexInfoRef(IndexInfo indexInfo)
2323
{
24-
private const string ToStringFormat = "Index '{0}' @ {1}";
25-
2624
/// <summary>
2725
/// Name of the index.
2826
/// </summary>
29-
public string IndexName { get; private set; }
27+
public string IndexName { get; } = indexInfo.Name;
3028

3129
/// <summary>
3230
/// Name of the reflecting type.
3331
/// </summary>
34-
public string TypeName { get; private set; }
32+
public string TypeName { get; } = indexInfo.ReflectedType.Name;
3533

36-
public TupleDescriptor KeyTupleDescriptor { get; private set; }
34+
public TupleDescriptor KeyTupleDescriptor { get; } = indexInfo.KeyTupleDescriptor;
3735

3836
/// <summary>
3937
/// Resolves this instance to <see cref="IndexInfo"/> object within specified <paramref name="model"/>.
4038
/// </summary>
4139
/// <param name="model">Domain model.</param>
4240
public IndexInfo Resolve(DomainModel model)
4341
{
44-
TypeInfo type;
45-
if (!model.Types.TryGetValue(TypeName, out type))
42+
if (!model.Types.TryGetValue(TypeName, out var type))
4643
throw new InvalidOperationException(string.Format(Strings.ExCouldNotResolveXYWithinDomain, "type", TypeName));
47-
IndexInfo index;
48-
if (!type.Indexes.TryGetValue(IndexName, out index)) {
49-
var hierarchy = type.Hierarchy;
50-
if (hierarchy != null && hierarchy.InheritanceSchema == InheritanceSchema.SingleTable && hierarchy.Root.Indexes.TryGetValue(IndexName, out index))
44+
if (!type.Indexes.TryGetValue(IndexName, out var index)) {
45+
if (type.Hierarchy is { } hierarchy && hierarchy.InheritanceSchema == InheritanceSchema.SingleTable && hierarchy.Root.Indexes.TryGetValue(IndexName, out index))
5146
return index;
5247
throw new InvalidOperationException(string.Format(Strings.ExCouldNotResolveXYWithinDomain, "index", IndexName));
5348
}
54-
5549
return index;
5650
}
5751

5852
/// <summary>
5953
/// Creates reference for <see cref="IndexInfo"/>.
6054
/// </summary>
61-
public static implicit operator IndexInfoRef (IndexInfo indexInfo)
62-
{
63-
return new IndexInfoRef(indexInfo);
64-
}
55+
public static implicit operator IndexInfoRef (IndexInfo indexInfo) => new(indexInfo);
6556

6657
#region Equality members, ==, !=
6758

6859
/// <inheritdoc/>
69-
public bool Equals(IndexInfoRef other)
70-
{
71-
if (other is null)
72-
return false;
73-
if (ReferenceEquals(this, other))
74-
return true;
75-
return
76-
other.IndexName==IndexName &&
77-
other.TypeName==TypeName;
78-
}
60+
public bool Equals(IndexInfoRef other) => IndexName == other.IndexName && TypeName == other.TypeName;
7961

8062
/// <inheritdoc/>
81-
public override bool Equals(object obj)
82-
{
83-
if (ReferenceEquals(this, obj))
84-
return true;
85-
return Equals(obj as IndexInfoRef);
86-
}
63+
public override bool Equals(object obj) => obj is IndexInfo other && Equals(other);
8764

8865
/// <inheritdoc/>
8966
public override int GetHashCode() => HashCode.Combine(IndexName, TypeName);
@@ -96,10 +73,7 @@ public override bool Equals(object obj)
9673
/// <returns>
9774
/// The result of the operator.
9875
/// </returns>
99-
public static bool operator ==(IndexInfoRef x, IndexInfoRef y)
100-
{
101-
return Equals(x, y);
102-
}
76+
public static bool operator ==(IndexInfoRef x, IndexInfoRef y) => x.Equals(y);
10377

10478
/// <summary>
10579
/// Implements the operator !=.
@@ -109,31 +83,11 @@ public override bool Equals(object obj)
10983
/// <returns>
11084
/// The result of the operator.
11185
/// </returns>
112-
public static bool operator !=(IndexInfoRef x, IndexInfoRef y)
113-
{
114-
return !Equals(x, y);
115-
}
86+
public static bool operator !=(IndexInfoRef x, IndexInfoRef y) => !x.Equals(y);
11687

11788
#endregion
11889

11990
/// <inheritdoc/>
120-
public override string ToString()
121-
{
122-
return string.Format(ToStringFormat, IndexName, TypeName);
123-
}
124-
125-
126-
// Constructors
127-
128-
/// <summary>
129-
/// Initializes a new instance of this class.
130-
/// </summary>
131-
/// <param name="indexInfo"><see cref="IndexInfo"/> object to make reference for.</param>
132-
public IndexInfoRef(IndexInfo indexInfo)
133-
{
134-
IndexName = indexInfo.Name;
135-
TypeName = indexInfo.ReflectedType.Name;
136-
KeyTupleDescriptor = indexInfo.KeyTupleDescriptor;
137-
}
91+
public override string ToString() => $"Index '{IndexName}' @ {TypeName}";
13892
}
13993
}

0 commit comments

Comments
 (0)