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 interpolated handler overload for Guard.IsTrue/IsFalse #70

Merged
merged 2 commits into from
Dec 29, 2021

Conversation

Sergio0694
Copy link
Member

This PR adds two new interpolated overloads for Guard.IsTrue and Guard.IsFalse.

API breakdown

namespace CommunityToolkit.Diagnostics
{
    public static partial class Guard
    {
        public static void IsTrue([DoesNotReturnIf(false)] bool value, string name, [InterpolatedStringHandlerArgument("value")] ref IsTrueInterpolatedStringHandler message);
        public static void IsFalse([DoesNotReturnIf(true)] bool value, string name, [InterpolatedStringHandlerArgument("value")] ref IsFalseInterpolatedStringHandler message);

        [EditorBrowsable(EditorBrowsableState.Never)]
        public struct IsTrueInterpolatedStringHandler
        {
            public IsTrueInterpolatedStringHandler(int literalLength, int formattedCount, bool condition, out bool shouldAppend);

            public void AppendLiteral(string value);
            public void AppendFormatted<T>(T value);
            public void AppendFormatted<T>(T value, string? format);
            public void AppendFormatted<T>(T value, int alignment);
            public void AppendFormatted<T>(T value, int alignment, string? format);
            public void AppendFormatted(ReadOnlySpan<char> value);
            public void AppendFormatted(ReadOnlySpan<char> value, int alignment = 0, string? format = null);
            public void AppendFormatted(string? value);
            public void AppendFormatted(string? value, int alignment = 0, string? format = null);
            public void AppendFormatted(object? value, int alignment = 0, string? format = null);
        }

        [EditorBrowsable(EditorBrowsableState.Never)]
        public struct IsFalseInterpolatedStringHandler
        {
            public IsFalseInterpolatedStringHandler(int literalLength, int formattedCount, bool condition, out bool shouldAppend);

            public void AppendLiteral(string value);
            public void AppendFormatted<T>(T value);
            public void AppendFormatted<T>(T value, string? format);
            public void AppendFormatted<T>(T value, int alignment);
            public void AppendFormatted<T>(T value, int alignment, string? format);
            public void AppendFormatted(ReadOnlySpan<char> value);
            public void AppendFormatted(ReadOnlySpan<char> value, int alignment = 0, string? format = null);
            public void AppendFormatted(string? value);
            public void AppendFormatted(string? value, int alignment = 0, string? format = null);
            public void AppendFormatted(object? value, int alignment = 0, string? format = null);
        }
    }
}

@Sergio0694 Sergio0694 added feature 💡 A new feature being implemented optimization ☄ Performance or memory usage improvements diagnostics 🔬 Issues/PRs for the Diagnostics package labels Dec 20, 2021
@Sergio0694 Sergio0694 merged commit 88f2a07 into main Dec 29, 2021
@delete-merged-branch delete-merged-branch bot deleted the dev/guard-assert-interpolated-handlers branch December 29, 2021 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostics 🔬 Issues/PRs for the Diagnostics package feature 💡 A new feature being implemented optimization ☄ Performance or memory usage improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants