Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<UseArtifactsOutput>true</UseArtifactsOutput>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
<PropertyGroup>
<UseArtifactsOutput>true</UseArtifactsOutput>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
33 changes: 18 additions & 15 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<Project>
<Import Project="$(MSBuildThisFileDirectory)PackageRedirects.props" Condition="Exists('$(MSBuildThisFileDirectory)PackageRedirects.props')" />
<ItemGroup>
<!-- Remove all items from PackageReference if they are in the PackageRedirect ItemGroup with a matching PackageName
<Import
Project="$(MSBuildThisFileDirectory)PackageRedirects.props"
Condition="Exists('$(MSBuildThisFileDirectory)PackageRedirects.props')"
/>
<ItemGroup>
<!-- Remove all items from PackageReference if they are in the PackageRedirect ItemGroup with a matching PackageName
element. Then add a ProjectReference to the project with the item identity in PackageRedirect. -->
<_ExcludePackage Include="@(PackageRedirect)" Exclude="@(PackageReference)">
<MatchOnMetadata>PackageName</MatchOnMetadata>
<ProjectPath>%(PackageName)</ProjectPath>
</_ExcludePackage>
<_ExcludeProjects Include ="@(_ExcludePackage->Metadata('ProjectPath'))" />
<ProjectReference Include="@(PackageRedirect)" Exclude="@(_ExcludeProjects)">
<ReferenceOutputAssembly>%(PackageRedirect.ReferenceOutputAssembly)</ReferenceOutputAssembly>
<ItemOutputGroup>%(PackageRedirect.ItemOutputGroup)</ItemOutputGroup>
</ProjectReference>
<_ExcludePackage Include="@(PackageRedirect)" Exclude="@(PackageReference)">
<MatchOnMetadata>PackageName</MatchOnMetadata>
<ProjectPath>%(PackageName)</ProjectPath>
</_ExcludePackage>
<_ExcludeProjects Include="@(_ExcludePackage->Metadata('ProjectPath'))" />
<ProjectReference Include="@(PackageRedirect)" Exclude="@(_ExcludeProjects)">
<ReferenceOutputAssembly>%(PackageRedirect.ReferenceOutputAssembly)</ReferenceOutputAssembly>
<ItemOutputGroup>%(PackageRedirect.ItemOutputGroup)</ItemOutputGroup>
</ProjectReference>

<PackageReference Remove="%(PackageRedirect.PackageName)" />
</ItemGroup>
</Project>
<PackageReference Remove="%(PackageRedirect.PackageName)" />
</ItemGroup>
</Project>
5 changes: 4 additions & 1 deletion nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
<add
key="dotnet-eng"
value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json"
/>
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
3 changes: 0 additions & 3 deletions src/Async/StaticCs.Async.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Nullable>enable</Nullable>
Expand All @@ -18,6 +17,4 @@
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="/" />
</ItemGroup>


</Project>
42 changes: 26 additions & 16 deletions src/Async/TaskScope.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -14,7 +13,10 @@ public sealed class TaskScope

private TaskScope() { }

public static async Task With(Func<TaskScope, Task> action, Action<OperationCanceledException>? onCanceled = null)
public static async Task With(
Func<TaskScope, Task> action,
Action<OperationCanceledException>? onCanceled = null
)
{
var scope = new TaskScope();
try
Expand All @@ -37,7 +39,7 @@ public static async Task With(Func<TaskScope, Task> action, Action<OperationCanc
throw new AggregateException(e, backgroundException);
}
}
if (await scope.CancelAndGather() is (true, {} ex))
if (await scope.CancelAndGather() is (true, { } ex))
{
throw ex;
}
Expand Down Expand Up @@ -75,7 +77,10 @@ public static async Task With(Func<TaskScope, Task> action, Action<OperationCanc
return (false, null);
case TaskStatus.Canceled:
List<OperationCanceledException>? unhandledCancels = null;
foreach (var ex in (IEnumerable<Exception>?)t.Exception?.InnerExceptions ?? Array.Empty<Exception>())
foreach (
var ex in (IEnumerable<Exception>?)t.Exception?.InnerExceptions
?? Array.Empty<Exception>()
)
{
// Filter out all cancellations that are owned by this scope
if (ex is OperationCanceledException e && e.CancellationToken != _cts.Token)
Expand Down Expand Up @@ -130,18 +135,23 @@ public Task Run(Func<Task> action)
throw new InvalidOperationException("TaskScope has ended.");
}

var task = Task.Factory.StartNew(async () =>
{
try
{
await action();
}
catch when (CancelAndRethrow(this))
{
throw new Exception("Unreachable");
}
}, TaskCreationOptions.AttachedToParent).Unwrap();
var task = Task
.Factory.StartNew(
async () =>
{
try
{
await action();
}
catch when (CancelAndRethrow(this))
{
throw new Exception("Unreachable");
}
},
TaskCreationOptions.AttachedToParent
)
.Unwrap();
_tasks.Add(task);
return task;
}
}
}
2 changes: 1 addition & 1 deletion src/Collections/EnumerableEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ public static class EnumerableEx2

return null;
}
}
}
21 changes: 15 additions & 6 deletions src/Collections/EqArray.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using System;
using System.Collections;
using System.Collections.Generic;
Expand All @@ -12,8 +11,11 @@ namespace StaticCs.Collections;
public static class EqArray
{
public static EqArray<T> ToEq<T>(this IEnumerable<T> array) => new(array.ToImmutableArray());

public static EqArray<T> ToEq<T>(this ImmutableArray<T> array) => new(array);

public static EqArray<T> Create<T>(params T[] array) => ImmutableArray.Create(array).ToEq();

public static EqArray<T> Create<T>(ReadOnlySpan<T> span) => ImmutableArray.Create(span).ToEq();
}

Expand All @@ -24,6 +26,7 @@ public static class EqArray
public readonly struct EqArray<T> : IReadOnlyCollection<T>, IEquatable<EqArray<T>>
{
private readonly ImmutableArray<T> value;

public EqArray(ImmutableArray<T> value)
{
this.value = value;
Expand Down Expand Up @@ -72,22 +75,26 @@ public readonly record struct SerializeImpl<T, TWrap>(EqArray<T> Value) : ISeria
{
public void Serialize(ISerializer serializer)
{
EnumerableHelpers.SerializeSpan<T, TWrap>(typeof(EqArray<T>).Name, Value.Array.AsSpan(), serializer);
EnumerableHelpers.SerializeSpan<T, TWrap>(
typeof(EqArray<T>).Name,
Value.Array.AsSpan(),
serializer
);
}
}

public readonly record struct DeserializeImpl<T, TWrap> : IDeserialize<EqArray<T>>
where TWrap : IDeserialize<T>
{
static EqArray<T> IDeserialize<EqArray<T>>.Deserialize<D>(ref D deserializer)
{
return deserializer.DeserializeEnumerable<
EqArray<T>,
Visitor>(new Visitor());
return deserializer.DeserializeEnumerable<EqArray<T>, Visitor>(new Visitor());
}

private struct Visitor : IDeserializeVisitor<EqArray<T>>
{
public string ExpectedTypeName => typeof(ImmutableArray<T>).ToString();

EqArray<T> IDeserializeVisitor<EqArray<T>>.VisitEnumerable<D>(ref D d)
{
ImmutableArray<T>.Builder builder;
Expand All @@ -107,7 +114,9 @@ EqArray<T> IDeserializeVisitor<EqArray<T>>.VisitEnumerable<D>(ref D d)
}
if (size >= 0 && builder.Count != size)
{
throw new InvalidDeserializeValueException($"Expected {size} items, found {builder.Count}");
throw new InvalidDeserializeValueException(
$"Expected {size} items, found {builder.Count}"
);
}
return new(builder.ToImmutable());
}
Expand Down
2 changes: 0 additions & 2 deletions src/Collections/StaticCs.Collections.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<Version>1.1.0</Version>
Expand All @@ -15,5 +14,4 @@
</PackageReference>
<PackageReference Include="Serde" Version="0.5.3" />
</ItemGroup>

</Project>
Loading