4
4
// Created by: Dmitri Maximov
5
5
// Created: 2007.09.12
6
6
7
- using System ;
8
- using System . Collections . Generic ;
9
7
using System . Text . RegularExpressions ;
10
8
using Xtensive . Orm . Building . Definitions ;
11
9
using Xtensive . Orm . Internals ;
14
12
15
13
namespace Xtensive . Orm . Building
16
14
{
17
- internal class Validator
15
+ internal class Validator ( IEnumerable < Type > validFieldTypes )
18
16
{
19
- private readonly HashSet < Type > validFieldTypes ;
20
- private readonly Regex columnNamingRule ;
21
- private readonly Regex typeNamingRule ;
22
- private readonly Regex fieldNamingRule ;
17
+ private static readonly Regex ColumnNamingRule = new ( @"^[\w][\w\-\.]*$" , RegexOptions . Compiled | RegexOptions . CultureInvariant ) ;
18
+ private readonly Regex TypeNamingRule = new ( @"^[\w][\w\-\.\(\),]*$" , RegexOptions . Compiled | RegexOptions . CultureInvariant ) ;
19
+ private readonly Regex FieldNamingRule = new ( @"^[\w][\w\-\.]*$" , RegexOptions . Compiled | RegexOptions . CultureInvariant ) ;
20
+
21
+ private readonly HashSet < Type > validFieldTypes = new ( validFieldTypes ) { WellKnownOrmTypes . Key } ;
23
22
24
23
/// <summary>
25
24
/// Determines whether the specified name is valid.
@@ -41,13 +40,13 @@ public void ValidateName(string name, ValidationRule rule)
41
40
case ValidationRule . Type :
42
41
case ValidationRule . Schema :
43
42
case ValidationRule . Database :
44
- namingRule = typeNamingRule ;
43
+ namingRule = TypeNamingRule ;
45
44
break ;
46
45
case ValidationRule . Field :
47
- namingRule = fieldNamingRule ;
46
+ namingRule = FieldNamingRule ;
48
47
break ;
49
48
case ValidationRule . Column :
50
- namingRule = columnNamingRule ;
49
+ namingRule = ColumnNamingRule ;
51
50
break ;
52
51
default :
53
52
throw new ArgumentOutOfRangeException ( ) ;
@@ -257,17 +256,6 @@ internal void EnsureIsNullable(Type valueType)
257
256
}
258
257
}
259
258
260
- // Type initializer
261
-
262
- public Validator ( IEnumerable < Type > validFieldTypes )
263
- {
264
- columnNamingRule = new Regex ( @"^[\w][\w\-\.]*$" , RegexOptions . Compiled | RegexOptions . CultureInvariant ) ;
265
- typeNamingRule = new Regex ( @"^[\w][\w\-\.\(\),]*$" , RegexOptions . Compiled | RegexOptions . CultureInvariant ) ;
266
- fieldNamingRule = new Regex ( @"^[\w][\w\-\.]*$" , RegexOptions . Compiled | RegexOptions . CultureInvariant ) ;
267
-
268
- this . validFieldTypes = new HashSet < Type > ( validFieldTypes ) { WellKnownOrmTypes . Key } ;
269
- }
270
-
271
259
public void ValidateHierarchyEquality ( TypeDef @interface , HierarchyDef first , HierarchyDef second )
272
260
{
273
261
// TypeId mode must match
@@ -277,17 +265,20 @@ public void ValidateHierarchyEquality(TypeDef @interface, HierarchyDef first, Hi
277
265
@interface . Name , first . Root . Name , second . Root . Name ) ) ;
278
266
}
279
267
268
+ var firstKeyFields = first . KeyFields ;
269
+ var secondKeyFields = second . KeyFields ;
270
+
280
271
// Number of key fields must match
281
- if ( first . KeyFields . Count != second . KeyFields . Count ) {
272
+ if ( firstKeyFields . Count != secondKeyFields . Count ) {
282
273
throw new DomainBuilderException ( string . Format (
283
274
Strings . ExImplementorsOfXInterfaceBelongToHierarchiesWithDifferentKeyStructureYZ ,
284
275
@interface . Name , first . Root . Name , second . Root . Name ) ) ;
285
276
}
286
277
287
278
// Type of each key field must match
288
- for ( var i = 0 ; i < first . KeyFields . Count ; i ++ ) {
289
- var masterField = first . Root . Fields [ first . KeyFields [ i ] . Name ] ;
290
- var candidateField = second . Root . Fields [ second . KeyFields [ i ] . Name ] ;
279
+ for ( var i = 0 ; i < firstKeyFields . Count ; i ++ ) {
280
+ var masterField = first . Root . Fields [ firstKeyFields [ i ] . Name ] ;
281
+ var candidateField = second . Root . Fields [ secondKeyFields [ i ] . Name ] ;
291
282
if ( masterField . ValueType != candidateField . ValueType ) {
292
283
throw new DomainBuilderException ( string . Format (
293
284
Strings . ExImplementorsOfXInterfaceBelongToHierarchiesWithDifferentKeyStructureYZ ,
0 commit comments