@@ -84,13 +84,14 @@ public ITermDictionary<JsonNode> ReplaceContent(string searchPattern, string rep
8484 var result = new Dictionary < string , JsonNode > ( ) ;
8585 foreach ( var ( key , value ) in this )
8686 {
87- if ( value . GetValueKind ( ) == JsonValueKind . String )
87+ if ( value is JsonValue jsonValue
88+ && jsonValue . TryGetValue < string > ( out var stringValue ) )
8889 {
89- var replaced = Regex . Replace ( value . GetValue < string > ( ) ,
90+ var replaced = Regex . Replace ( stringValue ,
9091 searchPattern ,
9192 replacement ,
9293 RegexOptions . Singleline ) ;
93- result . Add ( key , JsonValue . Create ( replaced ) ) ; // 我猜不会null罢
94+ result . Add ( key , JsonValue . Create ( replaced ) ! ) ; // 我猜不会null罢
9495 continue ;
9596 }
9697 result . Add ( key , value ) ;
@@ -100,8 +101,12 @@ public ITermDictionary<JsonNode> ReplaceContent(string searchPattern, string rep
100101
101102 public static ITermDictionary < JsonNode > Create ( IDictionary < string , string > nominalMapping )
102103 {
103- var transformed = nominalMapping
104- . ToDictionary ( p => p . Key , p => JsonValue . Create ( p . Value ) as JsonNode ) ;
104+ var query = from pair in nominalMapping
105+ let key = pair . Key
106+ let value = pair . Value
107+ let node = JsonValue . Create ( value ) !
108+ select ( key , node ) ;
109+ var transformed = query . ToDictionary ( _ => _ . key , _ => _ . node as JsonNode ) ;
105110 return new JsonDictionaryWrapper ( transformed ) ;
106111 }
107112 }
@@ -140,8 +145,7 @@ public TermMappingProvider(ITermDictionary<TValue> map, string destination)
140145 /// <inheritdoc/>
141146 public IResourceFileProvider ApplyTo ( IResourceFileProvider ? baseProvider , ApplyOptions options )
142147 {
143- if ( baseProvider is null )
144- return this ;
148+ if ( baseProvider is null ) return this ;
145149
146150 if ( baseProvider is not TermMappingProvider < TValue > baseMapping )
147151 throw new ArgumentException ( $ "Argument not an instance of { typeof ( TermMappingProvider < TValue > ) } .",
@@ -186,7 +190,7 @@ public IResourceFileProvider ReplaceDestination(string searchPattern, string rep
186190 RegexOptions . Singleline ) ) ;
187191
188192 /// <inheritdoc/>
189- public async Task WriteToArchiveAsync ( ZipArchive archive )
193+ public async Task WriteToArchive ( ZipArchive archive )
190194 {
191195 var destination = Destination . NormalizePath ( ) ;
192196 Log . Debug ( "[TermMappingProvider`1]写入路径 {0}" , destination ) ;
@@ -283,8 +287,7 @@ internal static Dictionary<string, string> DeserializeFromLang(string content)
283287 var splitPosition = line . IndexOf ( '=' ) ;
284288
285289 // https://github.com/CFPAOrg/Minecraft-Mod-Language-Package/pull/3272/files#r1461545452
286- if ( splitPosition == - 1 )
287- continue ;
290+ if ( splitPosition == - 1 ) continue ;
288291
289292 var key = line [ ..splitPosition ] ;
290293 var value = splitPosition + 1 < line . Length
0 commit comments