Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: SimonCropp/Polyfill
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6.0.0
Choose a base ref
...
head repository: SimonCropp/Polyfill
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6.1.0
Choose a head ref
  • 9 commits
  • 11 files changed
  • 1 contributor

Commits on Jul 19, 2024

  1. Verified

    This commit was signed with the committer’s verified signature.
    renovate-bot Mend Renovate
    Copy the full SHA
    d7d9400 View commit details
  2. TargetFrameworkUsage

    SimonCropp committed Jul 19, 2024
    Copy the full SHA
    8096baf View commit details

Commits on Jul 23, 2024

  1. refs and cleanup

    SimonCropp committed Jul 23, 2024
    Copy the full SHA
    2547da0 View commit details

Commits on Jul 26, 2024

  1. Update Directory.Packages.props

    SimonCropp committed Jul 26, 2024
    Copy the full SHA
    1c3e561 View commit details

Commits on Jul 28, 2024

  1. refs or cleanup

    SimonCropp committed Jul 28, 2024
    Copy the full SHA
    6cc08d5 View commit details

Commits on Aug 4, 2024

  1. Update Consume.cs

    SimonCropp committed Aug 4, 2024
    Copy the full SHA
    8551a5e View commit details
  2. Update Consume.cs

    SimonCropp committed Aug 4, 2024
    Copy the full SHA
    c619d52 View commit details
  3. Update Directory.Build.props

    SimonCropp committed Aug 4, 2024
    Copy the full SHA
    548be70 View commit details
  4. add XDocument.SaveAsync (#196)

    SimonCropp authored Aug 4, 2024
    Copy the full SHA
    6a2d4ac View commit details
2 changes: 1 addition & 1 deletion apiCount.include.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**API count: 299**
**API count: 302**
7 changes: 7 additions & 0 deletions api_list.include.md
Original file line number Diff line number Diff line change
@@ -380,6 +380,13 @@
* `Boolean TryFormat(Span<Char>, Int32&, ReadOnlySpan<Char>, IFormatProvider)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.uint64.tryformat)


#### Xml.Linq.XDocument

* `Task SaveAsync(Xml.XmlWriter, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xdocument.saveasync#system-xml-linq-xdocument-saveasync(system-xml-xmlwriter-system-threading-cancellationtoken))
* `Task SaveAsync(Stream, Xml.Linq.SaveOptions, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xdocument.saveasync#system-xml-linq-xdocument-saveasync(system-io-stream-system-xml-linq-saveoptions-system-threading-cancellationtoken))
* `Task SaveAsync(TextWriter, Xml.Linq.SaveOptions, CancellationToken)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xdocument.saveasync#system-xml-linq-xdocument-saveasync(system-io-textwriter-system-xml-linq-saveoptions-system-threading-cancellationtoken))


### Static helpers

#### EnumPolyfill
16 changes: 14 additions & 2 deletions src/Consume/Consume.cs
Original file line number Diff line number Diff line change
@@ -18,6 +18,10 @@
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using MemoryStream = System.IO.MemoryStream;

#pragma warning disable CS4014

class Consume
@@ -95,7 +99,7 @@ class Consume
typeof(List<string>).IsAssignableTo(typeof(string));
typeof(List<string>).IsAssignableTo(null);

var enumerable = (IEnumerable<string>)new List<string>
var enumerable = (IEnumerable<string>) new List<string>
{
"a",
"b"
@@ -417,7 +421,7 @@ public void CollectionBuilderAttribute()
public class MyCollection(ReadOnlySpan<int> initValues)
{
readonly int[] values = initValues.ToArray();
public IEnumerator<int> GetEnumerator() => ((IEnumerable<int>)values).GetEnumerator();
public IEnumerator<int> GetEnumerator() => ((IEnumerable<int>) values).GetEnumerator();

public static MyCollection Create(ReadOnlySpan<int> values) => new(values);
}
@@ -457,6 +461,14 @@ void GetMemberWithSameMetadataDefinitionAs(MemberInfo info)
var result = typeof(string).GetMemberWithSameMetadataDefinitionAs(info);
}

void XDocumentSaveAsync()
{
var document = new XDocument();
document.SaveAsync(new XmlTextWriter(null!), CancellationToken.None);
document.SaveAsync(new StringWriter(), SaveOptions.None, CancellationToken.None);
document.SaveAsync(new MemoryStream(), SaveOptions.None, CancellationToken.None);
}

#if FeatureMemory
void RandomNextBytesSpan()
{
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Version>6.0.0</Version>
<Version>6.1.0</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<PackageTags>Polyfill</PackageTags>
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
@@ -18,6 +18,6 @@
<NuGetAuditLevel>low</NuGetAuditLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsAotCompatible
Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>
Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</IsAotCompatible>
</PropertyGroup>
</Project>
8 changes: 4 additions & 4 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -8,12 +8,12 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="Mono.Cecil" Version="0.11.5" />
<PackageVersion Include="NUnit" Version="3.14.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="ProjectDefaults" Version="1.0.131" />
<PackageVersion Include="SimpleInfoName" Version="2.2.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="ProjectDefaults" Version="1.0.133" />
<PackageVersion Include="SimpleInfoName" Version="2.3.0" />
<PackageVersion Include="System.Memory" Version="4.5.5" />
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion src/Polyfill.sln
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsumeNoRefs", "ConsumeNoR
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsumeTasksWithNoMemory", "ConsumeTasksWithNoMemory\ConsumeTasksWithNoMemory.csproj", "{96EF1E04-5862-4D9E-B800-A6402F1ADF7A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TargetFrameowkUsage", "TargetFrameowkUsage\TargetFrameowkUsage.csproj", "{41CB5A0C-E0F5-4C5C-B2FC-9A289E8CFDF8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TargetFrameworkUsage", "TargetFrameworkUsage\TargetFrameworkUsage.csproj", "{41CB5A0C-E0F5-4C5C-B2FC-9A289E8CFDF8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2 changes: 1 addition & 1 deletion src/Polyfill.slnf
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
"projects": [
"Consume\\Consume.csproj",
"Polyfill\\Polyfill.csproj",
"TargetFrameowkUsage\\TargetFrameowkUsage.csproj",
"TargetFrameworkUsage\\TargetFrameworkUsage.csproj",
"Tests\\Tests.csproj"
]
}
83 changes: 83 additions & 0 deletions src/Polyfill/Polyfill_XDocument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// <auto-generated />
#pragma warning disable

#if NETFRAMEWORK || NETSTANDARD2_0

using System;
using System.Diagnostics.CodeAnalysis;
using System.Xml;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using Link = System.ComponentModel.DescriptionAttribute;

static partial class Polyfill
{
/// <summary>
/// Output this <see cref="XDocument"/> to an <see cref="XmlWriter"/>.
/// </summary>
/// <param name="writer">
/// The <see cref="XmlWriter"/> to output the XML to.
/// </param>
/// <param name="cancellationToken">
/// A cancellation token.
/// </param>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xdocument.saveasync#system-xml-linq-xdocument-saveasync(system-xml-xmlwriter-system-threading-cancellationtoken)")]
public static Task SaveAsync(
this XDocument target,
XmlWriter writer,
CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
target.Save(writer);
return Task.CompletedTask;
}

/// <summary>
/// Output this <see cref="XDocument"/> to a <see cref="Stream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="Stream"/> to output the XML to.
/// </param>
/// <param name="options">
/// If SaveOptions.DisableFormatting is enabled the output is not indented.
/// If SaveOptions.OmitDuplicateNamespaces is enabled duplicate namespace declarations will be removed.
/// </param>
/// <param name="cancellationToken">A cancellation token.</param>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xdocument.saveasync#system-xml-linq-xdocument-saveasync(system-io-stream-system-xml-linq-saveoptions-system-threading-cancellationtoken)")]
public static Task SaveAsync(
this XDocument target,
Stream stream,
SaveOptions options,
CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
target.Save(stream, options);
return Task.CompletedTask;
}

/// <summary>
/// Output this <see cref="XDocument"/> to a <see cref="TextWriter"/>.
/// </summary>
/// <param name="textWriter">
/// The <see cref="TextWriter"/> to output the XML to.
/// </param>
/// <param name="options">
/// If SaveOptions.DisableFormatting is enabled the output is not indented.
/// If SaveOptions.OmitDuplicateNamespaces is enabled duplicate namespace declarations will be removed.
/// </param>
/// <param name="cancellationToken">A cancellation token.</param>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xdocument.saveasync#system-xml-linq-xdocument-saveasync(system-io-textwriter-system-xml-linq-saveoptions-system-threading-cancellationtoken)")]
public static Task SaveAsync(
this XDocument target,
TextWriter textWriter,
SaveOptions options,
CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
target.Save(textWriter, options);
return Task.CompletedTask;
}
}
#endif
1 change: 0 additions & 1 deletion src/Shared.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -157,7 +157,6 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_BINARY_OPSIGN/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_BINARY_PATTERN_OP/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_FIRST_METHOD_CALL/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_CHAINED_METHOD_CALLS/@EntryValue">CHOP_ALWAYS</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_MULTIPLE_TYPE_PARAMEER_CONSTRAINTS_STYLE/@EntryValue">CHOP_ALWAYS</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/JavaScriptCodeFormatting/WRAP_LINES/@EntryValue">False</s:Boolean>
40 changes: 40 additions & 0 deletions src/Tests/PolyfillTests_XDocument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Xml;
using System.Xml.Linq;

partial class PolyfillTests
{
[Test]
public async Task XDocumentSaveAsyncXmlWriter()
{
var document = GetXDocument();
var builder = new StringBuilder();
var settings = new XmlWriterSettings
{
OmitXmlDeclaration = true,
Indent = true,
Async = true
};

using var writer = XmlWriter.Create(builder, settings);
await document.SaveAsync(writer, Cancel.None);
await writer.FlushAsync();
Assert.AreEqual("<Child />", builder.ToString());
}

[Test]
public async Task XDocumentSaveAsyncStream()
{
var document = GetXDocument();
using var stream = new MemoryStream();

await document.SaveAsync(stream, SaveOptions.DisableFormatting, Cancel.None);
stream.Position = 0;
using var reader = new StreamReader(stream);
var result = await reader.ReadToEndAsync();

Assert.AreEqual("<?xml version=\"1.0\" encoding=\"utf-8\"?><Child />", result);
}

static XDocument GetXDocument() =>
new(new XElement("Child"));
}