@@ -8,54 +8,38 @@ namespace RelogicLabs.JsonSchema.Tree;
88public class RuntimeContext
99{
1010 private readonly FunctionManager _functionManager ;
11-
11+ private readonly PragmaManager _pragmaManager ;
12+
1213 internal MessageFormatter MessageFormatter { get ; set ; }
1314 public bool ThrowException { get ; set ; }
14- public Dictionary < string , JPragma > Pragmas { get ; }
1515 public Dictionary < JAlias , JValidator > Definitions { get ; }
1616 public Queue < Exception > Exceptions { get ; }
17-
18- public bool IgnoreUndefinedProperties
19- => GetPragmaValue < bool > ( nameof ( IgnoreUndefinedProperties ) ) ;
20- public double FloatingPointTolerance
21- => GetPragmaValue < double > ( nameof ( FloatingPointTolerance ) ) ;
22- public bool IgnoreObjectPropertyOrder
23- => GetPragmaValue < bool > ( nameof ( IgnoreObjectPropertyOrder ) ) ;
17+
18+ public bool IgnoreUndefinedProperties => _pragmaManager . IgnoreUndefinedProperties ;
19+ public double FloatingPointTolerance => _pragmaManager . FloatingPointTolerance ;
20+ public bool IgnoreObjectPropertyOrder => _pragmaManager . IgnoreObjectPropertyOrder ;
21+
2422
2523 internal RuntimeContext ( MessageFormatter messageFormatter , bool throwException )
2624 {
2725 _functionManager = new FunctionManager ( this ) ;
26+ _pragmaManager = new PragmaManager ( ) ;
2827 MessageFormatter = messageFormatter ;
2928 ThrowException = throwException ;
30- Pragmas = new Dictionary < string , JPragma > ( ) ;
3129 Definitions = new Dictionary < JAlias , JValidator > ( ) ;
3230 Exceptions = new Queue < Exception > ( ) ;
3331 }
34-
35- private T GetPragmaValue < T > ( string name )
36- {
37- var entry = PragmaDescriptor . From ( name ) ;
38- Pragmas . TryGetValue ( entry ! . Name , out var pragma ) ;
39- return pragma == null ? ( ( PragmaProfile < T > ) entry ) . DefaultValue
40- : ( ( IPragmaValue < T > ) pragma . Value ) . Value ;
41- }
42-
43- public JPragma AddPragma ( JPragma pragma )
44- {
45- if ( Pragmas . ContainsKey ( pragma . Name ) )
46- throw new DuplicatePragmaException ( MessageFormatter . FormatForSchema (
47- PRAG03 , $ "Duplication found for { pragma . GetOutline ( ) } ", pragma . Context ) ) ;
48- Pragmas . Add ( pragma . Name , pragma ) ;
49- return pragma ;
50- }
32+
33+ public JPragma AddPragma ( JPragma pragma ) => _pragmaManager . AddPragma ( pragma ) ;
34+ public T GetPragmaValue < T > ( string name ) => _pragmaManager . GetPragmaValue < T > ( name ) ;
5135
5236 public JInclude AddClass ( JInclude include )
5337 {
5438 AddClass ( include . ClassName , include . Context ) ;
5539 return include ;
5640 }
5741
58- public void AddClass ( string className , Context ? context = null )
42+ public void AddClass ( string className , Context ? context = null )
5943 => _functionManager . AddClass ( className , context ) ;
6044
6145 public bool InvokeFunction ( JFunction function , JNode target )
@@ -66,15 +50,15 @@ public JDefinition AddDefinition(JDefinition definition)
6650 if ( Definitions . TryGetValue ( definition . Alias , out var previous ) )
6751 throw new DuplicateDefinitionException ( MessageFormatter . FormatForSchema (
6852 DEFI01 , $ "Duplicate definition of { definition . Alias
69- } is found and already defined as { previous . GetOutline ( ) } ",
53+ } is found and already defined as { previous . GetOutline ( ) } ",
7054 definition . Context ) ) ;
7155 Definitions . Add ( definition . Alias , definition . Validator ) ;
7256 return definition ;
7357 }
74-
75- internal bool AreEqual ( double value1 , double value2 )
58+
59+ internal bool AreEqual ( double value1 , double value2 )
7660 => Math . Abs ( value1 - value2 ) < FloatingPointTolerance ;
77-
61+
7862 internal bool FailWith ( Exception exception )
7963 {
8064 if ( ThrowException ) throw exception ;
0 commit comments