@@ -19,71 +19,48 @@ namespace Xtensive.Orm.Model
19
19
/// </summary>
20
20
[ Serializable ]
21
21
[ DebuggerDisplay ( "IndexName = {IndexName}, TypeName = {TypeName}" ) ]
22
- public sealed class IndexInfoRef
22
+ public readonly struct IndexInfoRef ( IndexInfo indexInfo )
23
23
{
24
- private const string ToStringFormat = "Index '{0}' @ {1}" ;
25
-
26
24
/// <summary>
27
25
/// Name of the index.
28
26
/// </summary>
29
- public string IndexName { get ; private set ; }
27
+ public string IndexName { get ; } = indexInfo . Name ;
30
28
31
29
/// <summary>
32
30
/// Name of the reflecting type.
33
31
/// </summary>
34
- public string TypeName { get ; private set ; }
32
+ public string TypeName { get ; } = indexInfo . ReflectedType . Name ;
35
33
36
- public TupleDescriptor KeyTupleDescriptor { get ; private set ; }
34
+ public TupleDescriptor KeyTupleDescriptor { get ; } = indexInfo . KeyTupleDescriptor ;
37
35
38
36
/// <summary>
39
37
/// Resolves this instance to <see cref="IndexInfo"/> object within specified <paramref name="model"/>.
40
38
/// </summary>
41
39
/// <param name="model">Domain model.</param>
42
40
public IndexInfo Resolve ( DomainModel model )
43
41
{
44
- TypeInfo type ;
45
- if ( ! model . Types . TryGetValue ( TypeName , out type ) )
42
+ if ( ! model . Types . TryGetValue ( TypeName , out var type ) )
46
43
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 ) )
51
46
return index ;
52
47
throw new InvalidOperationException ( string . Format ( Strings . ExCouldNotResolveXYWithinDomain , "index" , IndexName ) ) ;
53
48
}
54
-
55
49
return index ;
56
50
}
57
51
58
52
/// <summary>
59
53
/// Creates reference for <see cref="IndexInfo"/>.
60
54
/// </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 ) ;
65
56
66
57
#region Equality members, ==, !=
67
58
68
59
/// <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 ;
79
61
80
62
/// <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 ) ;
87
64
88
65
/// <inheritdoc/>
89
66
public override int GetHashCode ( ) => HashCode . Combine ( IndexName , TypeName ) ;
@@ -96,10 +73,7 @@ public override bool Equals(object obj)
96
73
/// <returns>
97
74
/// The result of the operator.
98
75
/// </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 ) ;
103
77
104
78
/// <summary>
105
79
/// Implements the operator !=.
@@ -109,31 +83,11 @@ public override bool Equals(object obj)
109
83
/// <returns>
110
84
/// The result of the operator.
111
85
/// </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 ) ;
116
87
117
88
#endregion
118
89
119
90
/// <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 } ";
138
92
}
139
93
}
0 commit comments