Skip to content

Commit 3333bf5

Browse files
committed
switch to the new NuGet package with public API
1 parent b752057 commit 3333bf5

File tree

71 files changed

+293
-3376
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+293
-3376
lines changed

Winforms.sln

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrimTestBinaryDeserializati
177177
EndProject
178178
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BinaryFormatTests", "src\System.Private.Windows.Core\tests\BinaryFormatTests\BinaryFormatTests.csproj", "{57EC5288-9513-46CF-8FB7-626199690D90}"
179179
EndProject
180-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Runtime.Serialization.BinaryFormat", "src\System.Runtime.Serialization.BinaryFormat\System.Runtime.Serialization.BinaryFormat.csproj", "{DC3DD357-7FB4-4384-92DC-5D34864D010B}"
181-
EndProject
182180
Global
183181
GlobalSection(SolutionConfigurationPlatforms) = preSolution
184182
Debug|Any CPU = Debug|Any CPU
@@ -983,22 +981,6 @@ Global
983981
{57EC5288-9513-46CF-8FB7-626199690D90}.Release|x64.Build.0 = Release|Any CPU
984982
{57EC5288-9513-46CF-8FB7-626199690D90}.Release|x86.ActiveCfg = Release|Any CPU
985983
{57EC5288-9513-46CF-8FB7-626199690D90}.Release|x86.Build.0 = Release|Any CPU
986-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
987-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Debug|Any CPU.Build.0 = Debug|Any CPU
988-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Debug|arm64.ActiveCfg = Debug|Any CPU
989-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Debug|arm64.Build.0 = Debug|Any CPU
990-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Debug|x64.ActiveCfg = Debug|Any CPU
991-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Debug|x64.Build.0 = Debug|Any CPU
992-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Debug|x86.ActiveCfg = Debug|Any CPU
993-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Debug|x86.Build.0 = Debug|Any CPU
994-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Release|Any CPU.ActiveCfg = Release|Any CPU
995-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Release|Any CPU.Build.0 = Release|Any CPU
996-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Release|arm64.ActiveCfg = Release|Any CPU
997-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Release|arm64.Build.0 = Release|Any CPU
998-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Release|x64.ActiveCfg = Release|Any CPU
999-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Release|x64.Build.0 = Release|Any CPU
1000-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Release|x86.ActiveCfg = Release|Any CPU
1001-
{DC3DD357-7FB4-4384-92DC-5D34864D010B}.Release|x86.Build.0 = Release|Any CPU
1002984
EndGlobalSection
1003985
GlobalSection(SolutionProperties) = preSolution
1004986
HideSolutionNode = FALSE
@@ -1062,7 +1044,6 @@ Global
10621044
{55F3174F-C1FE-4C8F-AF71-2512630088F8} = {583F1292-AE8D-4511-B8D8-A81FE4642DDC}
10631045
{CFBCC732-C988-4FE7-A21B-98A142365374} = {680FB14C-7B0C-4D63-9F1A-18ACCDB0F52A}
10641046
{57EC5288-9513-46CF-8FB7-626199690D90} = {583F1292-AE8D-4511-B8D8-A81FE4642DDC}
1065-
{DC3DD357-7FB4-4384-92DC-5D34864D010B} = {77FEDB47-F7F6-490D-AF7C-ABB4A9E0B9D7}
10661047
EndGlobalSection
10671048
GlobalSection(ExtensibilityGlobals) = postSolution
10681049
SolutionGuid = {7B1B0433-F612-4E5A-BE7E-FCF5B9F6E136}

src/System.Private.Windows.Core/src/System.Private.Windows.Core.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828

2929
<ItemGroup>
3030
<PackageReference Include="Microsoft.Windows.CsWin32" Version="$(MicrosoftWindowsCsWin32PackageVersion)" PrivateAssets="all" />
31-
</ItemGroup>
32-
33-
<ItemGroup>
34-
<ProjectReference Include="..\..\System.Runtime.Serialization.BinaryFormat\System.Runtime.Serialization.BinaryFormat.csproj" />
31+
<PackageReference Include="System.Formats.Nrbf" Version="9.0.0-preview.7.24372.7" />
3532
</ItemGroup>
3633

3734
<ItemGroup>

src/System.Private.Windows.Core/src/System/Windows/Forms/BinaryFormat/BinaryFormattedObject.IParseState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Runtime.Serialization.BinaryFormat;
4+
using System.Formats.Nrbf;
55

66
namespace System.Windows.Forms.BinaryFormat;
77

@@ -13,7 +13,7 @@ internal sealed partial class BinaryFormattedObject
1313
internal interface IParseState
1414
{
1515
BinaryReader Reader { get; }
16-
IReadOnlyDictionary<int, SerializationRecord> RecordMap { get; }
16+
IReadOnlyDictionary<SerializationRecordId, SerializationRecord> RecordMap { get; }
1717
Options Options { get; }
1818
ITypeResolver TypeResolver { get; }
1919
}

src/System.Private.Windows.Core/src/System/Windows/Forms/BinaryFormat/BinaryFormattedObject.ParseState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Runtime.Serialization.BinaryFormat;
4+
using System.Formats.Nrbf;
55

66
namespace System.Windows.Forms.BinaryFormat;
77

@@ -21,7 +21,7 @@ public ParseState(BinaryReader reader, BinaryFormattedObject format)
2121
}
2222

2323
public BinaryReader Reader { get; }
24-
public IReadOnlyDictionary<int, SerializationRecord> RecordMap => _format.RecordMap;
24+
public IReadOnlyDictionary<SerializationRecordId, SerializationRecord> RecordMap => _format.RecordMap;
2525
public Options Options => _format._options;
2626
public ITypeResolver TypeResolver => _format.TypeResolver;
2727
}

src/System.Private.Windows.Core/src/System/Windows/Forms/BinaryFormat/BinaryFormattedObject.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Reflection;
55
using System.Runtime.ExceptionServices;
66
using System.Runtime.Serialization;
7-
using System.Runtime.Serialization.BinaryFormat;
7+
using System.Formats.Nrbf;
88

99
namespace System.Windows.Forms.BinaryFormat;
1010

@@ -41,7 +41,7 @@ public BinaryFormattedObject(Stream stream, Options? options = null)
4141

4242
try
4343
{
44-
RootRecord = PayloadReader.Read(stream, out var readonlyRecordMap, leaveOpen: true);
44+
RootRecord = NrbfDecoder.Decode(stream, out var readonlyRecordMap, leaveOpen: true);
4545
RecordMap = readonlyRecordMap;
4646
}
4747
catch (Exception ex) when (ex is ArgumentException or InvalidCastException or ArithmeticException or IOException)
@@ -63,7 +63,7 @@ public object Deserialize()
6363
{
6464
try
6565
{
66-
return Deserializer.Deserializer.Deserialize(RootRecord.ObjectId, RecordMap, TypeResolver, _options);
66+
return Deserializer.Deserializer.Deserialize(RootRecord.Id, RecordMap, TypeResolver, _options);
6767
}
6868
catch (Exception ex) when (ex is ArgumentException or InvalidCastException or ArithmeticException or IOException)
6969
{
@@ -85,7 +85,7 @@ public object Deserialize()
8585
/// Gets a record by it's identifier. Not all records have identifiers, only ones that
8686
/// can be referenced by other records.
8787
/// </summary>
88-
public SerializationRecord this[Id id] => RecordMap[id];
88+
public SerializationRecord this[SerializationRecordId id] => RecordMap[id];
8989

90-
public IReadOnlyDictionary<int, SerializationRecord> RecordMap { get; }
90+
public IReadOnlyDictionary<SerializationRecordId, SerializationRecord> RecordMap { get; }
9191
}

src/System.Private.Windows.Core/src/System/Windows/Forms/BinaryFormat/BinaryFormattedObjectExtensions.cs

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System.Collections;
55
using System.Drawing;
6-
using System.Runtime.Serialization.BinaryFormat;
6+
using System.Formats.Nrbf;
77

88
namespace System.Windows.Forms.BinaryFormat;
99

@@ -38,7 +38,7 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? va
3838
value = default;
3939

4040
if (format.RootRecord is not ClassRecord classInfo
41-
|| !classInfo.IsTypeNameMatching(typeof(PointF))
41+
|| !classInfo.TypeNameMatches(typeof(PointF))
4242
|| !classInfo.HasMember("x")
4343
|| !classInfo.HasMember("y"))
4444
{
@@ -63,7 +63,7 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? va
6363
value = default;
6464

6565
if (format.RootRecord is not ClassRecord classInfo
66-
|| !classInfo.IsTypeNameMatching(typeof(RectangleF))
66+
|| !classInfo.TypeNameMatches(typeof(RectangleF))
6767
|| !classInfo.HasMember("x")
6868
|| !classInfo.HasMember("y")
6969
|| !classInfo.HasMember("width")
@@ -92,12 +92,12 @@ public static bool TryGetPrimitiveType(this BinaryFormattedObject format, [NotNu
9292

9393
static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? value)
9494
{
95-
if (format.RootRecord.RecordType is RecordType.BinaryObjectString)
95+
if (format.RootRecord.RecordType is SerializationRecordType.BinaryObjectString)
9696
{
9797
value = ((PrimitiveTypeRecord<string>)format.RootRecord).Value;
9898
return true;
9999
}
100-
else if (format.RootRecord.RecordType is RecordType.MemberPrimitiveTyped)
100+
else if (format.RootRecord.RecordType is SerializationRecordType.MemberPrimitiveTyped)
101101
{
102102
value = GetMemberPrimitiveTypedValue(format.RootRecord);
103103
return true;
@@ -110,7 +110,7 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? va
110110

111111
internal static object GetMemberPrimitiveTypedValue(this SerializationRecord record)
112112
{
113-
Debug.Assert(record.RecordType is RecordType.MemberPrimitiveTyped);
113+
Debug.Assert(record.RecordType is SerializationRecordType.MemberPrimitiveTyped);
114114

115115
return record switch
116116
{
@@ -162,22 +162,22 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? li
162162
// BinaryFormatter serializes the entire backing array, so we need to trim it down to the size of the list.
163163
list = arrayRecord switch
164164
{
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),
181181
_ => throw new InvalidOperationException()
182182
};
183183

@@ -197,18 +197,18 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? va
197197
value = null;
198198

199199
if (format.RootRecord is not ClassRecord classInfo
200-
|| !classInfo.IsTypeNameMatching(typeof(ArrayList))
200+
|| !classInfo.TypeNameMatches(typeof(ArrayList))
201201
|| !classInfo.HasMember("_items")
202202
|| !classInfo.HasMember("_size")
203203
|| 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
205205
|| size > arrayRecord.Length)
206206
{
207207
return false;
208208
}
209209

210210
ArrayList arrayList = new(size);
211-
object?[] array = arrayRecord.ToArray(maxLength: size);
211+
object?[] array = arrayRecord.GetArray();
212212
for (int i = 0; i < size; i++)
213213
{
214214
if (array[i] is SerializationRecord)
@@ -241,22 +241,22 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? va
241241

242242
value = format.RootRecord switch
243243
{
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(),
260260
_ => throw new InvalidOperationException()
261261
};
262262

@@ -285,23 +285,23 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? ha
285285
{
286286
hashtable = null;
287287

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
291289
|| format.RootRecord is not ClassRecord classInfo
292-
|| !classInfo.IsTypeNameMatching(typeof(Hashtable))
290+
|| !classInfo.TypeNameMatches(typeof(Hashtable))
293291
|| !classInfo.HasMember("Keys")
294292
|| !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
297297
|| keysRecord.Length != valuesRecord.Length)
298298
{
299299
return false;
300300
}
301301

302302
Hashtable temp = new((int)keysRecord.Length);
303-
object?[] keys = keysRecord.ToArray(maxLength: Array.MaxLength);
304-
object?[] values = valuesRecord.ToArray(maxLength: Array.MaxLength);
303+
object?[] keys = keysRecord.GetArray();
304+
object?[] values = valuesRecord.GetArray();
305305
for (int i = 0; i < keys.Length; i++)
306306
{
307307
object? key = keys[i];
@@ -334,7 +334,7 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? ex
334334
exception = null;
335335

336336
if (format.RootRecord is not ClassRecord classInfo
337-
|| classInfo.IsTypeNameMatching(typeof(NotSupportedException)))
337+
|| classInfo.TypeNameMatches(typeof(NotSupportedException)))
338338
{
339339
return false;
340340
}
@@ -360,5 +360,5 @@ public static bool TryGetFrameworkObject(
360360
|| format.TryGetNotSupportedException(out value);
361361

362362
private static bool IsPrimitiveArrayRecord(SerializationRecord serializationRecord)
363-
=> serializationRecord.RecordType is RecordType.ArraySingleString or RecordType.ArraySinglePrimitive;
363+
=> serializationRecord.RecordType is SerializationRecordType.ArraySingleString or SerializationRecordType.ArraySinglePrimitive;
364364
}

0 commit comments

Comments
 (0)