@@ -75,32 +75,53 @@ public class RequestHandlerSettings
75
75
[ DefaultValue ( StaticEnableDefaultCharReplacements ) ]
76
76
public bool EnableDefaultCharReplacements { get ; set ; } = StaticEnableDefaultCharReplacements ;
77
77
78
+ private IEnumerable < CharItem > _charCollection ;
79
+
78
80
/// <summary>
79
81
/// Add additional character replacements, or override defaults
80
82
/// </summary>
81
- public IEnumerable < CharItem > CharCollection { get ; set ; }
83
+ public IEnumerable < CharItem > CharCollection
84
+ {
85
+ get
86
+ {
87
+ // This is pretty ugly, but necessary.
88
+ // Essentially the config binding will only run properly if we return null the first time this is invoked.
89
+ // Otherwise whatever we return will just be used and user specific bindings won't overwrite the existing ones.
90
+ // However the next time this get is invoked, for instance in DefaultShortStringHelper we want to actually run the GetCharReplacements
91
+ // To make sure that the default bindings is used if configured to do so.
92
+ // Therefore we set _charCollection to be something, and still return null, to trick dotnet to actually read the config.
93
+ if ( _charCollection is null )
94
+ {
95
+ _charCollection = Enumerable . Empty < CharItem > ( ) ;
96
+ return null ;
97
+ }
98
+
99
+ return GetCharReplacements ( ) ;
100
+ }
101
+
102
+ set => _charCollection = value ;
103
+ }
82
104
83
105
/// <summary>
84
106
/// Get concatenated user and default character replacements
85
107
/// taking into account <see cref="EnableDefaultCharReplacements"/>
86
108
/// </summary>
87
- public IEnumerable < CharItem > GetCharReplacements ( )
109
+ private IEnumerable < CharItem > GetCharReplacements ( )
88
110
{
89
111
// TODO We need to special handle ":", as this character is special in keys
90
-
91
112
if ( ! EnableDefaultCharReplacements )
92
113
{
93
- return CharCollection ;
114
+ return _charCollection ?? Enumerable . Empty < CharItem > ( ) ;
94
115
}
95
116
96
- if ( CharCollection == null || ! CharCollection . Any ( ) )
117
+ if ( _charCollection == null || ! _charCollection . Any ( ) )
97
118
{
98
119
return DefaultCharCollection ;
99
120
}
100
121
101
- foreach ( var defaultReplacement in DefaultCharCollection )
122
+ foreach ( CharItem defaultReplacement in DefaultCharCollection )
102
123
{
103
- foreach ( var userReplacement in CharCollection )
124
+ foreach ( CharItem userReplacement in _charCollection )
104
125
{
105
126
if ( userReplacement . Char == defaultReplacement . Char )
106
127
{
@@ -109,7 +130,7 @@ public IEnumerable<CharItem> GetCharReplacements()
109
130
}
110
131
}
111
132
112
- var mergedCollections = DefaultCharCollection . Union < CharItem > ( CharCollection , new CharacterReplacementEqualityComparer ( ) ) ;
133
+ IEnumerable < CharItem > mergedCollections = DefaultCharCollection . Union < CharItem > ( _charCollection , new CharacterReplacementEqualityComparer ( ) ) ;
113
134
114
135
return mergedCollections ;
115
136
}
0 commit comments