Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ResourceManager and interpolated string overloads #159

Merged
merged 8 commits into from
Dec 20, 2024
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
3 changes: 3 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<LangVersion Condition="'$(Language)'=='C#'">13</LangVersion>
<LangVersion Condition="'$(Language)'=='VB'">16.9</LangVersion>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Update="*.resx" EmitFormatMethods="true" AsConstants="$(ResxAsConstants)" />
</ItemGroup>
<ItemGroup>
<!-- Avoid compile error about missing namespace when combining ImplicitUsings with .NET Framework target frameworks. -->
<Using Remove="System.Net.Http" Condition="'$(TargetFrameworkIdentifier)'=='.NETFramework'" />
Expand Down
5 changes: 4 additions & 1 deletion Validation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{223AEE15-59AF-40A6-BCBA-78D2A3CA598D}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
Directory.Packages.props = Directory.Packages.props
azure-pipelines\dotnet.yml = azure-pipelines\dotnet.yml
global.json = global.json
LICENSE.txt = LICENSE.txt
LICENSE = LICENSE
nuget.config = nuget.config
README.md = README.md
version.json = version.json
Expand Down
9 changes: 7 additions & 2 deletions docfx/docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@

## High performance

* Highly-tuned success paths minimize the perf impact of calling these APIs.
* Absolutely no allocations in success paths on .NET 9, and very few (if any) on older runtimes.
The APIs are highly-tuned success paths minimize the perf impact of calling these APIs.
There are absolutely no allocations in success paths on .NET 9, and very few (if any) on older runtimes.

* Optimized interpolated strings support so you can use `$"The value {value} is too low"` without any allocations unless the assertion fails.
* Optimized ResourceManager access to avoid loading a string resource unless the assertion fails.
* C# 13 `params ReadOnlySpan<object?>` overloads on .NET 9 to avoid allocations in success paths when many formatting arguments are required.
* Several small formatting argument count overloads to avoid array allocations in success paths on older runtimes.
4 changes: 2 additions & 2 deletions src/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Andrew Arnott. All rights reserved.
// Licensed under the Ms-PL license. See LICENSE.txt file in the project root for full license information.
// Licensed under the Ms-PL license. See LICENSE file in the project root for full license information.

#if NET45_OR_GREATER || NETSTANDARD1_1_OR_GREATER
#if NET45_OR_GREATER || NETSTANDARD || NET
using System.Runtime.InteropServices;

[assembly: DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
Expand Down
3 changes: 0 additions & 3 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
<Compile Include="$(MSBuildThisFileDirectory)AssemblyInfo.cs" Condition=" '$(Language)'=='C#' " />
<Compile Include="$(MSBuildThisFileDirectory)AssemblyInfo.vb" Condition=" '$(Language)'=='VB' " />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="*.resx" EmitFormatMethods="true" />
</ItemGroup>

<Import Project="$([MSBuild]::GetPathOfFileAbove($(MSBuildThisFile), $(MSBuildThisFileDirectory)..))" />
</Project>
2 changes: 1 addition & 1 deletion src/Validation/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Andrew Arnott. All rights reserved.
// Licensed under the Ms-PL license. See LICENSE.txt file in the project root for full license information.
// Licensed under the Ms-PL license. See LICENSE file in the project root for full license information.

using System.Resources;
using System.Security;
Expand Down
81 changes: 40 additions & 41 deletions src/Validation/Assumes.InternalErrorException.cs
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
// Copyright (c) Andrew Arnott. All rights reserved.
// Licensed under the Ms-PL license. See LICENSE.txt file in the project root for full license information.
// Licensed under the Ms-PL license. See LICENSE file in the project root for full license information.

namespace Validation
{
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;

namespace Validation;

/// <content>
/// Contains the inner exception thrown by Assumes.
/// </content>
public partial class Assumes
/// <content>
/// Contains the inner exception thrown by Assumes.
/// </content>
public partial class Assumes
{
/// <summary>
/// The exception that is thrown when an internal assumption failed.
/// </summary>
[Serializable]
[SuppressMessage("Microsoft.Design", "CA1064:ExceptionsShouldBePublic", Justification = "Internal exceptions should not be caught.")]
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", Justification = "This is an internal exception type and we don't use the recommended ctors.")]
private sealed class InternalErrorException : Exception
{
/// <summary>
/// The exception that is thrown when an internal assumption failed.
/// Initializes a new instance of the <see cref="InternalErrorException"/> class.
/// </summary>
[Serializable]
[SuppressMessage("Microsoft.Design", "CA1064:ExceptionsShouldBePublic", Justification = "Internal exceptions should not be caught.")]
[SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors", Justification = "This is an internal exception type and we don't use the recommended ctors.")]
private sealed class InternalErrorException : Exception
[DebuggerStepThrough]
public InternalErrorException(string? message = null)
: base(message ?? Strings.InternalExceptionMessage)
{
/// <summary>
/// Initializes a new instance of the <see cref="InternalErrorException"/> class.
/// </summary>
[DebuggerStepThrough]
public InternalErrorException(string? message = null)
: base(message ?? Strings.InternalExceptionMessage)
{
}
}

/// <summary>
/// Initializes a new instance of the <see cref="InternalErrorException"/> class.
/// </summary>
[DebuggerStepThrough]
public InternalErrorException(string? message, Exception? innerException)
: base(message ?? Strings.InternalExceptionMessage, innerException)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="InternalErrorException"/> class.
/// </summary>
[DebuggerStepThrough]
public InternalErrorException(string? message, Exception? innerException)
: base(message ?? Strings.InternalExceptionMessage, innerException)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="InternalErrorException"/> class.
/// </summary>
[DebuggerStepThrough]
/// <summary>
/// Initializes a new instance of the <see cref="InternalErrorException"/> class.
/// </summary>
[DebuggerStepThrough]
#if NET
[Obsolete]
[Obsolete]
#endif
private InternalErrorException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
private InternalErrorException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
Loading