Skip to content

Commit f29acba

Browse files
authored
Replace binary formatter (#8532)
* Replace BF for string input * Replacing BF * Updated BinaryFormattedObjectExtension * Replacing BF in DataStreams * Fixing Build for test * Updating comments * Adding fall back to BinaryFormatter * Adding UnitTest setup * Adding more BinaryFormatWriter test * Adding more unit tests * Adding BinaryFormattedObjectTests * Replacing Binaries before Unit Tests * Updating copy-wpf.ps1 * Resolving Replace binaries issue * Adding UnitTest setup * Adding more BinaryFormatWriter test * Adding more unit tests * Adding BinaryFormattedObjectTests * Replacing Binaries before Unit Tests * Updating copy-wpf.ps1 * Resolving Replace binaries issue * excluding DirectWriteForwarder for copy command * disable replace naive binaries * updating args data type * Replace BF for string input * Replacing BF * Updated BinaryFormattedObjectExtension * Replacing BF in DataStreams * Fixing Build for test * Updating comments * Adding fall back to BinaryFormatter * Adding UnitTest setup * Adding more BinaryFormatWriter test * Adding more unit tests * Adding BinaryFormattedObjectTests * Replacing Binaries before Unit Tests * Updating copy-wpf.ps1 * Resolving Replace binaries issue * excluding DirectWriteForwarder for copy command * Adding UnitTest setup * Adding more BinaryFormatWriter test * Adding more unit tests * disable replace naive binaries * updating args data type * updating pipeline-pr.yml * Replace BF for string input * Replacing BF * Updated BinaryFormattedObjectExtension * Replacing BF in DataStreams * Fixing Build for test * Updating comments * Adding fall back to BinaryFormatter * Adding UnitTest setup * Adding more BinaryFormatWriter test * Adding more unit tests * Adding BinaryFormattedObjectTests * Replacing Binaries before Unit Tests * Updating copy-wpf.ps1 * Resolving Replace binaries issue * excluding DirectWriteForwarder for copy command * Adding UnitTest setup * Adding more BinaryFormatWriter test * Adding more unit tests * disable replace naive binaries * updating args data type * updating pipeline-pr.yml * Replace BF for string input * Replacing BF * Replacing BF in DataStreams * Updating comments * Adding fall back to BinaryFormatter * Adding more BinaryFormatWriter test * Adding more unit tests * Adding more BinaryFormatWriter test * Adding more unit tests * Remove commented code and add correct indentation * Add "System.Runtime.Serialization.Formatters" reference in unit test * Disabling PresentationCore.Tests [Temp] * Revert Replace binaries before test * Fix indentation * Update Release | x86 type for SystemXamlTest * Update Write-host to wirte-debug for debug statement
1 parent 321e201 commit f29acba

File tree

87 files changed

+6424
-28
lines changed

Some content is hidden

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

87 files changed

+6424
-28
lines changed

Microsoft.Dotnet.Wpf.sln

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

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.28815.4
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34407.89
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Xaml", "src\Microsoft.DotNet.Wpf\src\System.Xaml\System.Xaml.csproj", "{9AC36357-34B7-40A1-95CA-FE9F46D089A7}"
77
EndProject
@@ -247,7 +247,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{34B64A4A
247247
EndProject
248248
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{A48B585E-6AB0-4F8D-8484-77F37CB44437}"
249249
EndProject
250-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Xaml.Tests", "src\Microsoft.DotNet.Wpf\tests\UnitTests\System.Xaml.Tests\System.Xaml.Tests.csproj", "{B2F2A89C-55C9-41B1-A645-0948609BD8BE}"
250+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFB}") = "System.Xaml.Tests", "src\Microsoft.DotNet.Wpf\tests\UnitTests\System.Xaml.Tests\System.Xaml.Tests.csproj", "{B2F2A89C-55C9-41B1-A645-0948609BD8BE}"
251251
EndProject
252252
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PresentationFramework.Fluent", "src\Microsoft.DotNet.Wpf\src\Themes\PresentationFramework.Fluent\PresentationFramework.Fluent.csproj", "{3F2C0E0E-BB13-46D9-8D9A-08256A49ECA9}"
253253
EndProject

eng/Versions.props

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@
6666
<PropertyGroup>
6767
<MicrosoftBuildFrameworkPackageVersion>15.9.20</MicrosoftBuildFrameworkPackageVersion>
6868
<MicrosoftBuildUtilitiesCorePackageVersion>15.9.20</MicrosoftBuildUtilitiesCorePackageVersion>
69-
<XUnitVersion>2.4.0</XUnitVersion>
70-
<XUnitRunnerConsoleVersion>$(XUnitVersion)</XUnitRunnerConsoleVersion>
71-
<XUnitRunnerVisualStudioVersion>$(XUnitVersion)</XUnitRunnerVisualStudioVersion>
69+
7270
<!--
7371
Also in global.json
7472
Used in Wpf.Cpp.PrivateTools.props/targets
@@ -87,9 +85,23 @@
8785
<PropertyGroup>
8886
<MicrosoftCodeAnalysisNetAnalyzersVersion>7.0.0</MicrosoftCodeAnalysisNetAnalyzersVersion>
8987
</PropertyGroup>
88+
<!-- XUnit-related (not extensions) -->
89+
<PropertyGroup>
90+
<XUnitVersion>2.6.1</XUnitVersion>
91+
<XUnitAssertVersion>$(XUnitVersion)</XUnitAssertVersion>
92+
<XUnitRunnerConsoleVersion>$(XUnitVersion)</XUnitRunnerConsoleVersion>
93+
<XUnitRunnerVisualStudioVersion>2.4.3</XUnitRunnerVisualStudioVersion>
94+
<XUnitExtensibilityExecutionVersion>$(XUnitVersion)</XUnitExtensibilityExecutionVersion>
95+
<XUnitStaFactPackageVersion>1.2.46-alpha</XUnitStaFactPackageVersion>
96+
</PropertyGroup>
9097
<!-- Test related -->
9198
<PropertyGroup>
9299
<MoqPackageVersion>4.10.0</MoqPackageVersion>
100+
<FluentAssertionsVersion>6.11.0</FluentAssertionsVersion>
101+
<SystemComponentModelTypeConverterTestDataVersion>8.0.0-beta.23107.1</SystemComponentModelTypeConverterTestDataVersion>
102+
<SystemDrawingCommonTestDataVersion>8.0.0-beta.23107.1</SystemDrawingCommonTestDataVersion>
103+
<SystemWindowsExtensionsTestDataVersion>8.0.0-beta.23107.1</SystemWindowsExtensionsTestDataVersion>
104+
<VerifyXunitVersion>14.2.0</VerifyXunitVersion>
93105
</PropertyGroup>
94106
<!-- Code Coverage -->
95107
<PropertyGroup>

eng/WpfArcadeSdk/Sdk/Sdk.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PropertyGroup>
1616
<GenXmlStringTable>$(WpfArcadeSdkToolsDir)GenXmlStringTable.pl</GenXmlStringTable>
1717
<LangVersion Condition="'$(LangVersion)'=='' and ($(PreReleaseVersionLabel.Contains('rc')) or $(PreReleaseVersionLabel.Contains('preview')) or $(PreReleaseVersionLabel.Contains('alpha')))">preview</LangVersion>
18-
<LangVersion Condition="'$(LangVersion)'==''">10</LangVersion>
18+
<LangVersion Condition="'$(LangVersion)'==''">11</LangVersion>
1919
<CLSCompliant Condition="'$(CLSCompliant)'==''">true</CLSCompliant>
2020
<IncludeDllSafeSearchPathAttribute Condition="'$(IncludeDllSafeSearchPathAttribute )'==''">true</IncludeDllSafeSearchPathAttribute>
2121

eng/copy-wpf.ps1

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,18 @@ function Print-Usage()
3030
Write-Host "*** Copy WPF files procedure ***"
3131

3232
$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
33+
Write-Debug ("Repo root = " + $RepoRoot)
3334
$Config = if ($release) { "Release" } else { "Debug" }
3435

35-
Write-Host "Target architecture - configuration: " $arch $Config
36+
Write-Debug ("Target architecture - configuration: " + $arch + $Config)
3637

3738
function CopyBinariesToLocation($location)
3839
{
3940
$locallyBuiltBinaryLocationBase = Join-Path $RepoRoot "artifacts\packaging"
41+
Write-Debug ("locallyBuiltBinaryLocationBase = " + $locallyBuiltBinaryLocationBase)
4042

41-
Write-Host "Copy native binaries..."
42-
CopyNativeBinariesToLocation $location $locallyBuiltBinaryLocationBase
43+
# Write-Host "Copy native binaries..."
44+
# CopyNativeBinariesToLocation $location $locallyBuiltBinaryLocationBase
4345

4446
Write-Host "Copy managed binaries..."
4547
CopyManagedBinariesToLocation $location $locallyBuiltBinaryLocationBase
@@ -53,8 +55,26 @@ function CopyNativeBinariesToLocation($location, $localBinLocation)
5355
# x64 - artifacts\packaging\Debug\x64\Microsoft.DotNet.Wpf.GitHub\lib\win-x64
5456

5557
$PackageName = "Microsoft.DotNet.Wpf.GitHub"
58+
$PackageName += if ($release) { "" } else { ".Debug" }
5659
$BinaryLocationInPackage = "win-$arch"
57-
CopyPackagedBinaries $location $localBinLocation $PackageName $BinaryLocationInPackage
60+
# CopyPackagedBinaries $location $localBinLocation $PackageName $BinaryLocationInPackage
61+
62+
$ArchFolder = if ($arch -eq "x86") { "" } else { "x64" }
63+
$BinLocation = [System.IO.Path]::Combine($localBinLocation, $Config, $ArchFolder, $packageName, "runtimes", $binaryLocationInPackage,"native" , "*")
64+
Write-Debug ("Native binLocation = " + $BinLocation)
65+
66+
if (Test-Path $BinLocation)
67+
{
68+
Copy-Item -path $BinLocation -include "*.dll","*.pdb" -Destination $location
69+
Write-Host "All files are copied" -ForegroundColor Green
70+
}
71+
else
72+
{
73+
Write-Host "Source files location unavailable: " $BinLocation -ForegroundColor Yellow -NoNewline
74+
Write-Host " Skip. No file has been copied."
75+
return
76+
}
77+
5878
}
5979
function CopyManagedBinariesToLocation($location, $localBinLocation)
6080
{
@@ -63,17 +83,20 @@ function CopyManagedBinariesToLocation($location, $localBinLocation)
6383
# x64 - artifacts\packaging\Debug\x64\Microsoft.DotNet.Wpf.GitHub\lib\net6.0
6484

6585
$PackageName = "Microsoft.DotNet.Wpf.GitHub"
66-
$BinaryLocationInPackage = "net8.0"
86+
$PackageName += if ($release) { "" } else { ".Debug" }
87+
$BinaryLocationInPackage = "net9.0"
6788
CopyPackagedBinaries $location $localBinLocation $PackageName $BinaryLocationInPackage
6889
}
6990

7091
function CopyPackagedBinaries($location, $localBinLocation, $packageName, $binaryLocationInPackage)
7192
{
7293
$ArchFolder = if ($arch -eq "x86") { "" } else { "x64" }
7394
$BinLocation = [System.IO.Path]::Combine($localBinLocation, $Config, $ArchFolder, $packageName, "lib", $binaryLocationInPackage, "*")
95+
Write-Debug ("binLocation = " + $BinLocation)
96+
7497
if (Test-Path $BinLocation)
7598
{
76-
Copy-Item -path $BinLocation -include "*.dll","*.pdb" -Destination $location
99+
Copy-Item -path $BinLocation -include "*.dll","*.pdb" -Destination $location -Exclude DirectWriteForwarder.*
77100
Write-Host "All files are copied" -ForegroundColor Green
78101
}
79102
else
@@ -153,7 +176,7 @@ elseif($testhost)
153176
else
154177
{
155178
$runtimeIdentifer = "win-$arch"
156-
$location = [System.IO.Path]::Combine($destination, "bin\Debug\net8.0", $runtimeIdentifer, "publish")
179+
$location = [System.IO.Path]::Combine($destination, "bin\Debug\net9.0", $runtimeIdentifer, "publish")
157180
if(![System.IO.Directory]::Exists($location))
158181
{
159182
Write-Host "App publishing directory unavailable: " $location -ForegroundColor Red

eng/pipeline.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,15 @@ jobs:
151151
# (!_HelixPipeline) ||
152152
# (_HelixPipeline && _PublicBuildPipeline && _ContinuousIntegrationTestsEnabled && _BuildConfig == Release)
153153
condition: or(ne(variables['_HelixPipeline'], 'true'), and(eq(variables['_HelixPipeline'], 'true') ,eq(variables['_BuildConfig'], 'Release'), eq(variables['_PublicBuildPipeline'], 'true'), eq(variables['_ContinuousIntegrationTestsEnabled'], 'true')))
154-
- script: eng\scripts\ciunittest.cmd -configuration $(_BuildConfig) -prepareMachine $(_PublishArgs) $(_SignArgs) $(_OfficialBuildIdArgs) $(_PlatformArgs) $(_InternalRuntimeDownloadArgs)
154+
155+
- script: eng\scripts\ciunittest.cmd
156+
-configuration $(_BuildConfig)
157+
-prepareMachine
158+
$(_PublishArgs)
159+
$(_SignArgs)
160+
$(_OfficialBuildIdArgs)
161+
$(_PlatformArgs)
162+
$(_InternalRuntimeDownloadArgs)
155163
displayName: Run xUnit Tests
156164
condition: and(or(ne(variables['_HelixPipeline'], 'true'), and(eq(variables['_HelixPipeline'], 'true') ,eq(variables['_BuildConfig'], 'Release'), eq(variables['_PublicBuildPipeline'], 'true'), eq(variables['_ContinuousIntegrationTestsEnabled'], 'true'))), ne(variables['_Platform'], 'arm64'))
157165
- task: PublishTestResults@2
@@ -193,6 +201,7 @@ jobs:
193201
targetType: 'inline'
194202
script: '.\eng\copy-wpf.ps1 -testhost -destination .dotnet -$(_BuildConfig) -arch $(_Platform)'
195203
condition: and(eq(variables['System.TeamProject'], 'public'), ne(variables['_Platform'], 'arm64'))
204+
196205
- task: DownloadPipelineArtifact@2
197206
displayName: Fetch Test Binaries
198207
inputs:

src/Microsoft.DotNet.Wpf/src/PresentationCore/OtherAssemblyAttrs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
[assembly:InternalsVisibleTo(BuildInfo.PresentationFrameworkSystemDrawing)]
1919
[assembly:InternalsVisibleTo(BuildInfo.SystemWindowsControlsRibbon)]
2020
[assembly:InternalsVisibleTo(BuildInfo.WindowsFormsIntegration)]
21-
21+
[assembly:InternalsVisibleTo("PresentationCore.Tests,PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
2222
[assembly: TypeForwardedTo(typeof(System.Windows.Markup.IUriContext))]
2323
[assembly: TypeForwardedTo(typeof(System.Windows.Media.TextFormattingMode))]
2424
[assembly: TypeForwardedTo(typeof(System.Windows.Input.ICommand))]

src/Microsoft.DotNet.Wpf/src/PresentationCore/PresentationCore.csproj

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<Compile Include="$(WpfCommonDir)src\System\SR.cs">
2626
<Link>Common\System\SR.cs</Link>
2727
</Compile>
28+
2829
<Compile Include="$(WpfCommonDir)\Graphics\wgx_error.cs" />
2930
<Compile Include="$(WpfCommonDir)\Graphics\wgx_render.cs" />
3031
<Compile Include="$(WpfCommonDir)\Graphics\wgx_exports.cs" />
@@ -333,6 +334,57 @@
333334
<Compile Include="System\Windows\DataFormat.cs" />
334335
<Compile Include="System\Windows\DataFormats.cs" />
335336
<Compile Include="System\Windows\dataobject.cs" />
337+
<Compile Include="System\Windows\BinaryFormat\BinaryFormatWriter.cs" />
338+
<Compile Include="System\Windows\BinaryFormat\BinaryFormatWriterScope.cs" />
339+
<Compile Include="System\Windows\BinaryFormat\ExceptionExtensions.cs" />
340+
<Compile Include="System\Windows\BinaryFormat\BinaryObjectString.cs" />
341+
<Compile Include="System\Windows\BinaryFormat\IBinaryFormatParseable.cs" />
342+
<Compile Include="System\Windows\BinaryFormat\IBinaryWriteable.cs" />
343+
<Compile Include="System\Windows\BinaryFormat\MemberTypeInfo.cs" />
344+
<Compile Include="System\Windows\BinaryFormat\Id.cs" />
345+
<Compile Include="System\Windows\BinaryFormat\IRecord.cs" />
346+
<Compile Include="System\Windows\BinaryFormat\RecordMap.cs" />
347+
<Compile Include="System\Windows\BinaryFormat\RecordType.cs" />
348+
<Compile Include="System\Windows\BinaryFormat\NullableAttributes.cs" />
349+
<Compile Include="System\Windows\BinaryFormat\ListConverterHelper.cs" />
350+
<Compile Include="System\Windows\BinaryFormat\FormatterConverterStub.cs" />
351+
<Compile Include="System\Windows\BinaryFormat\SerializationExtensions.cs" />
352+
<Compile Include="System\Windows\BinaryFormat\BinaryFormattedObject.cs" />
353+
<Compile Include="System\Windows\BinaryFormat\BinaryFormattedObjectExtensions.cs" />
354+
<Compile Include="System\Windows\BinaryFormat\MessageEnd.cs" />
355+
<Compile Include="System\Windows\BinaryFormat\Record.cs" />
356+
<Compile Include="System\Windows\BinaryFormat\BinaryType.cs" />
357+
<Compile Include="System\Windows\BinaryFormat\PrimitiveType.cs" />
358+
<Compile Include="System\Windows\BinaryFormat\Count.cs" />
359+
<Compile Include="System\Windows\BinaryFormat\NullRecord.cs" />
360+
<Compile Include="System\Windows\BinaryFormat\ObjectNull.cs" />
361+
<Compile Include="System\Windows\BinaryFormat\ArraySingleString.cs" />
362+
<Compile Include="System\Windows\BinaryFormat\ArrayRecord.cs" />
363+
<Compile Include="System\Windows\BinaryFormat\ArrayInfo.cs" />
364+
<Compile Include="System\Windows\BinaryFormat\ArraySingleObject.cs" />
365+
<Compile Include="System\Windows\BinaryFormat\ArraySinglePrimitive.cs" />
366+
<Compile Include="System\Windows\BinaryFormat\BinaryLibrary.cs" />
367+
<Compile Include="System\Windows\BinaryFormat\MemberReference.cs" />
368+
<Compile Include="System\Windows\BinaryFormat\MemberPrimitiveTyped.cs" />
369+
<Compile Include="System\Windows\BinaryFormat\BinaryArray.cs" />
370+
<Compile Include="System\Windows\BinaryFormat\ClassWithMembersAndTypes.cs" />
371+
<Compile Include="System\Windows\BinaryFormat\SystemClassWithMembersAndTypes.cs" />
372+
<Compile Include="System\Windows\BinaryFormat\ClassInfo.cs" />
373+
<Compile Include="System\Windows\BinaryFormat\ClassRecord.cs" />
374+
<Compile Include="System\Windows\BinaryFormat\ClassWithId.cs" />
375+
<Compile Include="System\Windows\BinaryFormat\TypeInfo.cs" />
376+
<Compile Include="System\Windows\BinaryFormat\ClassWithMembers.cs" />
377+
<Compile Include="System\Windows\BinaryFormat\SystemClassWithMembers.cs" />
378+
<Compile Include="System\Windows\BinaryFormat\SerializationHeader.cs" />
379+
<Compile Include="System\Windows\BinaryFormat\ClassTypeInfo.cs" />
380+
<Compile Include="System\Windows\BinaryFormat\BinaryArrayType.cs" />
381+
<Compile Include="System\Windows\BinaryFormat\BinaryReaderExtensions.cs" />
382+
<Compile Include="System\Windows\BinaryFormat\BinaryWriterExtensions.cs" />
383+
<Compile Include="System\Windows\BinaryFormat\IntrinsicExtensions.cs" />
384+
<Compile Include="System\Windows\BinaryFormat\NullRecord.ObjectNullMultiple.cs" />
385+
<Compile Include="System\Windows\BinaryFormat\NullRecord.ObjectNullMultiple256.cs" />
386+
<Compile Include="System\Windows\BinaryFormat\StringRecordsCollection.cs" />
387+
<Compile Include="System\Windows\BinaryFormat\ListConverter.cs" />
336388
<Compile Include="System\Windows\DataObjectCopyingEventArgs.cs" />
337389
<Compile Include="System\Windows\DataObjectEventArgs.cs" />
338390
<Compile Include="System\Windows\DataObjectPastingEventArgs.cs" />
@@ -1397,6 +1449,7 @@
13971449
<NetCoreReference Include="System.Diagnostics.Tools" />
13981450
<NetCoreReference Include="System.Diagnostics.TraceSource" />
13991451
<NetCoreReference Include="System.Diagnostics.Tracing" />
1452+
<NetCoreReference Include="System.Drawing.Primitives" />
14001453
<NetCoreReference Include="System.IO.FileSystem" />
14011454
<NetCoreReference Include="System.Memory" />
14021455
<NetCoreReference Include="System.Net.Primitives" />
@@ -1411,6 +1464,8 @@
14111464
<NetCoreReference Include="System.Text.Encoding.Extensions" />
14121465
<NetCoreReference Include="System.Text.RegularExpressions" />
14131466
<NetCoreReference Include="System.Threading" />
1467+
<NetCoreReference Include="System.Collections.Generic" />
1468+
<NetCoreReference Include="System.Linq" />
14141469
<NetCoreReference Include="System.Threading.Tasks" />
14151470
<NetCoreReference Include="System.Threading.Thread" />
14161471
<NetCoreReference Include="System.Threading.ThreadPool" />
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.IO;
5+
6+
namespace System.Windows
7+
{
8+
/// <summary>
9+
/// Array information structure.
10+
/// </summary>
11+
/// <remarks>
12+
/// <para>
13+
/// <see href="https://learn.microsoft.com/openspecs/windows_protocols/ms-nrbf/8fac763f-e46d-43a1-b360-80eb83d2c5fb">
14+
/// [MS-NRBF] 2.4.2.1
15+
/// </see>
16+
/// </para>
17+
/// </remarks>
18+
internal readonly struct ArrayInfo : IBinaryWriteable
19+
{
20+
public Id ObjectId { get; }
21+
public Count Length { get; }
22+
23+
public ArrayInfo(Id objectId, Count length)
24+
{
25+
Length = length;
26+
ObjectId = objectId;
27+
}
28+
29+
public static ArrayInfo Parse(BinaryReader reader, out Count length)
30+
{
31+
ArrayInfo arrayInfo = new(reader.ReadInt32(), reader.ReadInt32());
32+
length = arrayInfo.Length;
33+
return arrayInfo;
34+
}
35+
36+
public readonly void Write(BinaryWriter writer)
37+
{
38+
writer.Write(ObjectId);
39+
writer.Write(Length);
40+
}
41+
}
42+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
5+
using System.Collections.Generic;
6+
using System.Collections;
7+
using System.Linq;
8+
9+
namespace System.Windows
10+
{
11+
/// <summary>
12+
/// Base class for array records.
13+
/// </summary>
14+
/// <devdoc>
15+
/// <see href="https://learn.microsoft.com/openspecs/windows_protocols/ms-nrbf/f57d41e5-d3c0-4340-add8-fa4449a68d1c">
16+
/// [MS-NRBF] 2.4</see> describes how item records must follow the array record and how multiple null records
17+
/// can be coalesced into an <see cref="NullRecord.ObjectNullMultiple"/> or <see cref="NullRecord.ObjectNullMultiple256"/>
18+
/// record.
19+
/// </devdoc>
20+
internal abstract class ArrayRecord : Record, IEnumerable<object>
21+
{
22+
public ArrayInfo ArrayInfo { get; }
23+
24+
/// <summary>
25+
/// The array items.
26+
/// </summary>
27+
/// <remarks>
28+
/// <para>
29+
/// Multi-null records are always expanded to individual <see cref="ObjectNull"/> entries when reading.
30+
/// </para>
31+
/// </remarks>
32+
public IReadOnlyList<object> ArrayObjects { get; }
33+
34+
/// <summary>
35+
/// Identifier for the array.
36+
/// </summary>
37+
public Id ObjectId => ArrayInfo.ObjectId;
38+
39+
/// <summary>
40+
/// Length of the array.
41+
/// </summary>
42+
public Count Length => ArrayInfo.Length;
43+
44+
/// <summary>
45+
/// Returns the item at the given index.
46+
/// </summary>
47+
public object this[int index] => ArrayObjects[index];
48+
49+
public ArrayRecord(ArrayInfo arrayInfo, IReadOnlyList<object> arrayObjects)
50+
{
51+
if (arrayInfo.Length != arrayObjects.Count)
52+
{
53+
throw new ArgumentException($"{nameof(arrayInfo)} doesn't match count of {nameof(arrayObjects)}");
54+
}
55+
56+
ArrayInfo = arrayInfo;
57+
ArrayObjects = arrayObjects;
58+
}
59+
60+
IEnumerator<object> IEnumerable<object>.GetEnumerator() => ArrayObjects.GetEnumerator();
61+
IEnumerator IEnumerable.GetEnumerator() => ArrayObjects.GetEnumerator();
62+
}
63+
}

0 commit comments

Comments
 (0)