@@ -22,8 +22,8 @@ namespace Datamodel.Codecs
2222 [ CodecFormat ( "keyvalues2_noids" , 4 ) ]
2323 class KeyValues2 : ICodec
2424 {
25- static readonly Dictionary < Type , string > TypeNames = new ( ) ;
26- static readonly Dictionary < int , Type [ ] > ValidAttributes = new ( ) ;
25+ static readonly Dictionary < Type , string > TypeNames = [ ] ;
26+ static readonly Dictionary < int , Type [ ] > ValidAttributes = [ ] ;
2727 static KeyValues2 ( )
2828 {
2929 TypeNames [ typeof ( Element ) ] = "element" ;
@@ -131,7 +131,7 @@ public void Flush()
131131
132132 // Multi-referenced elements are written out as a separate block at the end of the file.
133133 // In-line only the id is written.
134- Dictionary < Element , int > ReferenceCount = new ( ) ;
134+ Dictionary < Element , int > ReferenceCount = [ ] ;
135135
136136 bool SupportsReferenceIds ;
137137
@@ -294,9 +294,8 @@ void WriteAttribute(string name, int encodingVersion, Type type, object value, b
294294
295295 value = FormattableString . Invariant ( FormattableStringFactory . Create ( matrixString ) ) ;
296296 }
297- else if ( value is QAngle qangle_value )
297+ else if ( value is QAngle castValue )
298298 {
299- var castValue = ( QAngle ) value ;
300299 value = FormattableString . Invariant ( $ "{ castValue . Pitch } { castValue . Yaw } { castValue . Roll } ") ;
301300 }
302301
@@ -354,7 +353,7 @@ public void Encode(Datamodel dm, string encoding, int encodingVersion, Stream st
354353 writer . Write ( String . Format ( CodecUtilities . HeaderPattern , encoding , encodingVersion , dm . Format , dm . FormatVersion ) ) ;
355354 writer . WriteLine ( ) ;
356355
357- ReferenceCount = new Dictionary < Element , int > ( ) ;
356+ ReferenceCount = [ ] ;
358357
359358 if ( encodingVersion >= 4 && dm . PrefixAttributes . Count > 0 )
360359 {
@@ -404,8 +403,8 @@ private class IntermediateData
404403 // these store element refs while we process the elements, once were done
405404 // we can go trough these and actually create the attributes
406405 // and add the elements to lists
407- public Dictionary < Element , List < ( string , Guid ) > > PropertiesToAdd = new ( ) ;
408- public Dictionary < IList , List < Guid > > ListRefs = new ( ) ;
406+ public Dictionary < Element , List < ( string , Guid ) > > PropertiesToAdd = [ ] ;
407+ public Dictionary < IList , List < Guid > > ListRefs = [ ] ;
409408
410409 public void HandleElementProp ( Element ? element , string attrName , Guid id )
411410 {
@@ -418,7 +417,7 @@ public void HandleElementProp(Element? element, string attrName, Guid id)
418417
419418 if ( attrList == null )
420419 {
421- attrList = new List < ( string , Guid ) > ( ) ;
420+ attrList = [ ] ;
422421 PropertiesToAdd . Add ( element , attrList ) ;
423422 }
424423
@@ -432,7 +431,7 @@ public void HandleListRefs(IList list, Guid id)
432431
433432 if ( guidList == null )
434433 {
435- guidList = new List < Guid > ( ) ;
434+ guidList = [ ] ;
436435 ListRefs . Add ( list , guidList ) ;
437436 }
438437
@@ -522,7 +521,7 @@ string Decode_NextToken(StreamReader reader)
522521 ConstructorInfo ? constructor = typeof ( Element ) . GetConstructor (
523522 BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic ,
524523 null ,
525- new Type [ ] { typeof ( Datamodel ) , typeof ( string ) , typeof ( Guid ) , typeof ( string ) } ,
524+ [ typeof ( Datamodel ) , typeof ( string ) , typeof ( Guid ) , typeof ( string ) ] ,
526525 null
527526 ) ;
528527
@@ -532,16 +531,13 @@ string Decode_NextToken(StreamReader reader)
532531 }
533532
534533 object uninitializedObject = RuntimeHelpers . GetUninitializedObject ( derivedType ) ;
535- constructor . Invoke ( uninitializedObject , new object [ ] { dataModel , elem_name , new Guid ( elem_id ) , elem_class } ) ;
534+ constructor . Invoke ( uninitializedObject , [ dataModel , elem_name , new Guid ( elem_id ) , elem_class ] ) ;
536535
537536 elem = ( Element ? ) uninitializedObject ;
538537 }
539538 }
540539
541- if ( elem == null )
542- {
543- elem = new Element ( dataModel , elem_name , new Guid ( elem_id ) , elem_class ) ;
544- }
540+ elem ??= new Element ( dataModel , elem_name , new Guid ( elem_id ) , elem_class ) ;
545541 }
546542
547543 continue ;
@@ -664,7 +660,7 @@ string Decode_NextToken(StreamReader reader)
664660 else if ( type == typeof ( TimeSpan ) )
665661 return TimeSpan . FromTicks ( ( long ) ( double . Parse ( value , CultureInfo . InvariantCulture ) * TimeSpan . TicksPerSecond ) ) ;
666662
667- var num_list = value . Split ( ( char [ ] ? ) null , StringSplitOptions . RemoveEmptyEntries ) ;
663+ var num_list = value . Split ( Array . Empty < char > ( ) , StringSplitOptions . RemoveEmptyEntries ) ;
668664
669665 if ( type == typeof ( Color ) )
670666 {
0 commit comments