44// Created by: Dmitri Maximov
55// Created: 2007.09.12
66
7- using System ;
8- using System . Collections . Generic ;
97using System . Text . RegularExpressions ;
108using Xtensive . Orm . Building . Definitions ;
119using Xtensive . Orm . Internals ;
1412
1513namespace Xtensive . Orm . Building
1614{
17- internal class Validator
15+ internal class Validator ( IEnumerable < Type > validFieldTypes )
1816 {
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 } ;
2322
2423 /// <summary>
2524 /// Determines whether the specified name is valid.
@@ -41,13 +40,13 @@ public void ValidateName(string name, ValidationRule rule)
4140 case ValidationRule . Type :
4241 case ValidationRule . Schema :
4342 case ValidationRule . Database :
44- namingRule = typeNamingRule ;
43+ namingRule = TypeNamingRule ;
4544 break ;
4645 case ValidationRule . Field :
47- namingRule = fieldNamingRule ;
46+ namingRule = FieldNamingRule ;
4847 break ;
4948 case ValidationRule . Column :
50- namingRule = columnNamingRule ;
49+ namingRule = ColumnNamingRule ;
5150 break ;
5251 default :
5352 throw new ArgumentOutOfRangeException ( ) ;
@@ -257,17 +256,6 @@ internal void EnsureIsNullable(Type valueType)
257256 }
258257 }
259258
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-
271259 public void ValidateHierarchyEquality ( TypeDef @interface , HierarchyDef first , HierarchyDef second )
272260 {
273261 // TypeId mode must match
@@ -277,17 +265,20 @@ public void ValidateHierarchyEquality(TypeDef @interface, HierarchyDef first, Hi
277265 @interface . Name , first . Root . Name , second . Root . Name ) ) ;
278266 }
279267
268+ var firstKeyFields = first . KeyFields ;
269+ var secondKeyFields = second . KeyFields ;
270+
280271 // Number of key fields must match
281- if ( first . KeyFields . Count != second . KeyFields . Count ) {
272+ if ( firstKeyFields . Count != secondKeyFields . Count ) {
282273 throw new DomainBuilderException ( string . Format (
283274 Strings . ExImplementorsOfXInterfaceBelongToHierarchiesWithDifferentKeyStructureYZ ,
284275 @interface . Name , first . Root . Name , second . Root . Name ) ) ;
285276 }
286277
287278 // 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 ] ;
291282 if ( masterField . ValueType != candidateField . ValueType ) {
292283 throw new DomainBuilderException ( string . Format (
293284 Strings . ExImplementorsOfXInterfaceBelongToHierarchiesWithDifferentKeyStructureYZ ,
0 commit comments