1
- // Copyright (C) 2014 Xtensive LLC.
2
- // All rights reserved .
3
- // For conditions of distribution and use, see license .
1
+ // Copyright (C) 2014-2022 Xtensive LLC.
2
+ // This code is distributed under MIT license terms .
3
+ // See the License.txt file in the project root for more information .
4
4
// Created by: Denis Krjuchkov
5
5
// Created: 2014.03.13
6
6
@@ -16,18 +16,18 @@ namespace Xtensive.Orm.Model
16
16
[ Serializable ]
17
17
public sealed class TypeIdRegistry : LockableBase
18
18
{
19
- private readonly Dictionary < TypeInfo , int > mapping ;
20
- private readonly Dictionary < int , TypeInfo > reverseMapping ;
19
+ private readonly Dictionary < TypeInfo , int > mapping = new ( ) ;
20
+ private readonly Dictionary < int , TypeInfo > reverseMapping = new ( ) ;
21
21
22
22
/// <summary>
23
23
/// Gets collection of registered types.
24
24
/// </summary>
25
- public IEnumerable < TypeInfo > Types { get { return mapping . Keys ; } }
25
+ public IEnumerable < TypeInfo > Types => mapping . Keys ;
26
26
27
27
/// <summary>
28
28
/// Gets collection of registered type identifiers.
29
29
/// </summary>
30
- public IEnumerable < int > TypeIdentifiers { get { return reverseMapping . Keys ; } }
30
+ public IEnumerable < int > TypeIdentifiers => reverseMapping . Keys ;
31
31
32
32
/// <summary>
33
33
/// Gets type identifier for the specified <paramref name="type"/>.
@@ -36,13 +36,11 @@ public sealed class TypeIdRegistry : LockableBase
36
36
/// <returns>Type identifier for the specified <paramref name="type"/>.</returns>
37
37
public int this [ TypeInfo type ]
38
38
{
39
- get
40
- {
39
+ get {
41
40
ArgumentValidator . EnsureArgumentNotNull ( type , "type" ) ;
42
- int result ;
43
- if ( ! mapping . TryGetValue ( type , out result ) )
44
- throw new KeyNotFoundException ( string . Format ( Strings . ExTypeXIsNotRegistered , type . Name ) ) ;
45
- return result ;
41
+ return ! mapping . TryGetValue ( type , out var result )
42
+ ? throw new KeyNotFoundException ( string . Format ( Strings . ExTypeXIsNotRegistered , type . Name ) )
43
+ : result ;
46
44
}
47
45
}
48
46
@@ -51,16 +49,10 @@ public int this[TypeInfo type]
51
49
/// </summary>
52
50
/// <param name="typeId">Type identifier to get type for.</param>
53
51
/// <returns>Type for the specified <paramref name="typeId"/>.</returns>
54
- public TypeInfo this [ int typeId ]
55
- {
56
- get
57
- {
58
- TypeInfo result ;
59
- if ( ! reverseMapping . TryGetValue ( typeId , out result ) )
60
- throw new KeyNotFoundException ( string . Format ( Strings . ExTypeIdXIsNotRegistered , typeId ) ) ;
61
- return result ;
62
- }
63
- }
52
+ public TypeInfo this [ int typeId ] =>
53
+ ! reverseMapping . TryGetValue ( typeId , out var result )
54
+ ? throw new KeyNotFoundException ( string . Format ( Strings . ExTypeIdXIsNotRegistered , typeId ) )
55
+ : result ;
64
56
65
57
/// <summary>
66
58
/// Checks if specified <paramref name="type"/> is registered.
@@ -86,10 +78,7 @@ public bool Contains(TypeInfo type)
86
78
public int GetTypeId ( TypeInfo type )
87
79
{
88
80
ArgumentValidator . EnsureArgumentNotNull ( type , "type" ) ;
89
- int result ;
90
- if ( ! mapping . TryGetValue ( type , out result ) )
91
- return TypeInfo . NoTypeId ;
92
- return result ;
81
+ return ! mapping . TryGetValue ( type , out var result ) ? TypeInfo . NoTypeId : result ;
93
82
}
94
83
95
84
/// <summary>
@@ -117,16 +106,5 @@ public void Register(int typeId, TypeInfo type)
117
106
mapping [ type ] = typeId ;
118
107
reverseMapping [ typeId ] = type ;
119
108
}
120
-
121
- // Constructors
122
-
123
- /// <summary>
124
- /// Initializes new instance of this type.
125
- /// </summary>
126
- public TypeIdRegistry ( )
127
- {
128
- mapping = new Dictionary < TypeInfo , int > ( ) ;
129
- reverseMapping = new Dictionary < int , TypeInfo > ( ) ;
130
- }
131
109
}
132
110
}
0 commit comments