3
3
4
4
using System . Collections ;
5
5
using System . Drawing ;
6
- using System . Runtime . Serialization . BinaryFormat ;
6
+ using System . Formats . Nrbf ;
7
7
8
8
namespace System . Windows . Forms . BinaryFormat ;
9
9
@@ -38,7 +38,7 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? va
38
38
value = default ;
39
39
40
40
if ( format . RootRecord is not ClassRecord classInfo
41
- || ! classInfo . IsTypeNameMatching ( typeof ( PointF ) )
41
+ || ! classInfo . TypeNameMatches ( typeof ( PointF ) )
42
42
|| ! classInfo . HasMember ( "x" )
43
43
|| ! classInfo . HasMember ( "y" ) )
44
44
{
@@ -63,7 +63,7 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? va
63
63
value = default ;
64
64
65
65
if ( format . RootRecord is not ClassRecord classInfo
66
- || ! classInfo . IsTypeNameMatching ( typeof ( RectangleF ) )
66
+ || ! classInfo . TypeNameMatches ( typeof ( RectangleF ) )
67
67
|| ! classInfo . HasMember ( "x" )
68
68
|| ! classInfo . HasMember ( "y" )
69
69
|| ! classInfo . HasMember ( "width" )
@@ -92,12 +92,12 @@ public static bool TryGetPrimitiveType(this BinaryFormattedObject format, [NotNu
92
92
93
93
static bool Get ( BinaryFormattedObject format , [ NotNullWhen ( true ) ] out object ? value )
94
94
{
95
- if ( format . RootRecord . RecordType is RecordType . BinaryObjectString )
95
+ if ( format . RootRecord . RecordType is SerializationRecordType . BinaryObjectString )
96
96
{
97
97
value = ( ( PrimitiveTypeRecord < string > ) format . RootRecord ) . Value ;
98
98
return true ;
99
99
}
100
- else if ( format . RootRecord . RecordType is RecordType . MemberPrimitiveTyped )
100
+ else if ( format . RootRecord . RecordType is SerializationRecordType . MemberPrimitiveTyped )
101
101
{
102
102
value = GetMemberPrimitiveTypedValue ( format . RootRecord ) ;
103
103
return true ;
@@ -110,7 +110,7 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? va
110
110
111
111
internal static object GetMemberPrimitiveTypedValue ( this SerializationRecord record )
112
112
{
113
- Debug . Assert ( record . RecordType is RecordType . MemberPrimitiveTyped ) ;
113
+ Debug . Assert ( record . RecordType is SerializationRecordType . MemberPrimitiveTyped ) ;
114
114
115
115
return record switch
116
116
{
@@ -162,22 +162,22 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? li
162
162
// BinaryFormatter serializes the entire backing array, so we need to trim it down to the size of the list.
163
163
list = arrayRecord switch
164
164
{
165
- ArrayRecord < string > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
166
- ArrayRecord < bool > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
167
- ArrayRecord < byte > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
168
- ArrayRecord < sbyte > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
169
- ArrayRecord < char > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
170
- ArrayRecord < short > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
171
- ArrayRecord < ushort > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
172
- ArrayRecord < int > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
173
- ArrayRecord < uint > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
174
- ArrayRecord < long > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
175
- ArrayRecord < ulong > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
176
- ArrayRecord < float > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
177
- ArrayRecord < double > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
178
- ArrayRecord < decimal > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
179
- ArrayRecord < TimeSpan > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
180
- ArrayRecord < DateTime > ar => ar . ToArray ( maxLength : Array . MaxLength ) . CreateTrimmedList ( size ) ,
165
+ SZArrayRecord < string > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
166
+ SZArrayRecord < bool > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
167
+ SZArrayRecord < byte > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
168
+ SZArrayRecord < sbyte > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
169
+ SZArrayRecord < char > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
170
+ SZArrayRecord < short > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
171
+ SZArrayRecord < ushort > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
172
+ SZArrayRecord < int > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
173
+ SZArrayRecord < uint > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
174
+ SZArrayRecord < long > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
175
+ SZArrayRecord < ulong > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
176
+ SZArrayRecord < float > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
177
+ SZArrayRecord < double > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
178
+ SZArrayRecord < decimal > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
179
+ SZArrayRecord < TimeSpan > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
180
+ SZArrayRecord < DateTime > ar => ar . GetArray ( ) . CreateTrimmedList ( size ) ,
181
181
_ => throw new InvalidOperationException ( )
182
182
} ;
183
183
@@ -197,18 +197,18 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? va
197
197
value = null ;
198
198
199
199
if ( format . RootRecord is not ClassRecord classInfo
200
- || ! classInfo . IsTypeNameMatching ( typeof ( ArrayList ) )
200
+ || ! classInfo . TypeNameMatches ( typeof ( ArrayList ) )
201
201
|| ! classInfo . HasMember ( "_items" )
202
202
|| ! classInfo . HasMember ( "_size" )
203
203
|| classInfo . GetRawValue ( "_size" ) is not int size
204
- || classInfo . GetRawValue ( "_items" ) is not ArrayRecord < object > arrayRecord
204
+ || classInfo . GetRawValue ( "_items" ) is not SZArrayRecord < object > arrayRecord
205
205
|| size > arrayRecord . Length )
206
206
{
207
207
return false ;
208
208
}
209
209
210
210
ArrayList arrayList = new ( size ) ;
211
- object ? [ ] array = arrayRecord . ToArray ( maxLength : size ) ;
211
+ object ? [ ] array = arrayRecord . GetArray ( ) ;
212
212
for ( int i = 0 ; i < size ; i ++ )
213
213
{
214
214
if ( array [ i ] is SerializationRecord )
@@ -241,22 +241,22 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? va
241
241
242
242
value = format . RootRecord switch
243
243
{
244
- ArrayRecord < string > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
245
- ArrayRecord < bool > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
246
- ArrayRecord < byte > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
247
- ArrayRecord < sbyte > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
248
- ArrayRecord < char > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
249
- ArrayRecord < short > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
250
- ArrayRecord < ushort > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
251
- ArrayRecord < int > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
252
- ArrayRecord < uint > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
253
- ArrayRecord < long > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
254
- ArrayRecord < ulong > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
255
- ArrayRecord < float > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
256
- ArrayRecord < double > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
257
- ArrayRecord < decimal > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
258
- ArrayRecord < TimeSpan > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
259
- ArrayRecord < DateTime > ar => ar . ToArray ( maxLength : Array . MaxLength ) ,
244
+ SZArrayRecord < string > ar => ar . GetArray ( ) ,
245
+ SZArrayRecord < bool > ar => ar . GetArray ( ) ,
246
+ SZArrayRecord < byte > ar => ar . GetArray ( ) ,
247
+ SZArrayRecord < sbyte > ar => ar . GetArray ( ) ,
248
+ SZArrayRecord < char > ar => ar . GetArray ( ) ,
249
+ SZArrayRecord < short > ar => ar . GetArray ( ) ,
250
+ SZArrayRecord < ushort > ar => ar . GetArray ( ) ,
251
+ SZArrayRecord < int > ar => ar . GetArray ( ) ,
252
+ SZArrayRecord < uint > ar => ar . GetArray ( ) ,
253
+ SZArrayRecord < long > ar => ar . GetArray ( ) ,
254
+ SZArrayRecord < ulong > ar => ar . GetArray ( ) ,
255
+ SZArrayRecord < float > ar => ar . GetArray ( ) ,
256
+ SZArrayRecord < double > ar => ar . GetArray ( ) ,
257
+ SZArrayRecord < decimal > ar => ar . GetArray ( ) ,
258
+ SZArrayRecord < TimeSpan > ar => ar . GetArray ( ) ,
259
+ SZArrayRecord < DateTime > ar => ar . GetArray ( ) ,
260
260
_ => throw new InvalidOperationException ( )
261
261
} ;
262
262
@@ -285,23 +285,23 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? ha
285
285
{
286
286
hashtable = null ;
287
287
288
- // Note that hashtables with custom comparers and/or hash code providers will have that information before
289
- // the value pair arrays.
290
- if ( format . RootRecord . RecordType != RecordType . SystemClassWithMembersAndTypes
288
+ if ( format . RootRecord . RecordType != SerializationRecordType . SystemClassWithMembersAndTypes
291
289
|| format . RootRecord is not ClassRecord classInfo
292
- || ! classInfo . IsTypeNameMatching ( typeof ( Hashtable ) )
290
+ || ! classInfo . TypeNameMatches ( typeof ( Hashtable ) )
293
291
|| ! classInfo . HasMember ( "Keys" )
294
292
|| ! classInfo . HasMember ( "Values" )
295
- || format [ 2 ] is not ArrayRecord < object ? > keysRecord
296
- || format [ 3 ] is not ArrayRecord < object ? > valuesRecord
293
+ // Note that hashtables with custom comparers and/or hash code providers will have non null Comparer
294
+ || classInfo . GetSerializationRecord ( "Comparer" ) is not null
295
+ || classInfo . GetSerializationRecord ( "Keys" ) is not SZArrayRecord < object ? > keysRecord
296
+ || classInfo . GetSerializationRecord ( "Values" ) is not SZArrayRecord < object ? > valuesRecord
297
297
|| keysRecord . Length != valuesRecord . Length )
298
298
{
299
299
return false ;
300
300
}
301
301
302
- Hashtable temp = new ( ( int ) keysRecord . Length ) ;
303
- object ? [ ] keys = keysRecord . ToArray ( maxLength : Array . MaxLength ) ;
304
- object ? [ ] values = valuesRecord . ToArray ( maxLength : Array . MaxLength ) ;
302
+ Hashtable temp = new ( keysRecord . Length ) ;
303
+ object ? [ ] keys = keysRecord . GetArray ( ) ;
304
+ object ? [ ] values = valuesRecord . GetArray ( ) ;
305
305
for ( int i = 0 ; i < keys . Length ; i ++ )
306
306
{
307
307
object ? key = keys [ i ] ;
@@ -334,7 +334,7 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? ex
334
334
exception = null ;
335
335
336
336
if ( format . RootRecord is not ClassRecord classInfo
337
- || classInfo . IsTypeNameMatching ( typeof ( NotSupportedException ) ) )
337
+ || classInfo . TypeNameMatches ( typeof ( NotSupportedException ) ) )
338
338
{
339
339
return false ;
340
340
}
@@ -360,5 +360,5 @@ public static bool TryGetFrameworkObject(
360
360
|| format . TryGetNotSupportedException ( out value ) ;
361
361
362
362
private static bool IsPrimitiveArrayRecord ( SerializationRecord serializationRecord )
363
- => serializationRecord . RecordType is RecordType . ArraySingleString or RecordType . ArraySinglePrimitive ;
363
+ => serializationRecord . RecordType is SerializationRecordType . ArraySingleString or SerializationRecordType . ArraySinglePrimitive ;
364
364
}
0 commit comments