-
Notifications
You must be signed in to change notification settings - Fork 225
Enable nullable referenrce types in DebugEngineHost #1592
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
Draft
gregg-miskelly
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
gregg-miskelly:NullableRef_EngineHost
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| global using static global::Microsoft.DebugEngineHost.NullableHelpers; | ||
|
|
||
| namespace Microsoft.DebugEngineHost | ||
| { | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using ConditionalAttribute = System.Diagnostics.ConditionalAttribute; | ||
| using SysDebug = System.Diagnostics.Debug; | ||
|
|
||
| #pragma warning disable 8763 // A method marked [DoesNotReturn] should not return. | ||
|
|
||
| /// <summary> | ||
| /// Helper class to support nullable reference work when compiling against .NET Standard / .NET Framework | ||
| /// </summary> | ||
| public static class NullableHelpers | ||
| { | ||
| /// <summary> | ||
| /// Wrapper around string.IsNullOrEmpty to add the `[NotNullWhen(false)]` annotation | ||
| /// </summary> | ||
| /// <param name="s">string to test</param> | ||
| /// <returns>True if the string is null or empty</returns> | ||
| static public bool IsNullOrEmpty([NotNullWhen(false)] string? s) | ||
| { | ||
| return string.IsNullOrEmpty(s); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Wrapper around string.IsNullOrWhiteSpace to add the `[NotNullWhen(false)]` annotation | ||
| /// </summary> | ||
| /// <param name="s">string to test</param> | ||
| /// <returns>True if the string is null, empty, or only whitespace</returns> | ||
| static public bool IsNullOrWhiteSpace([NotNullWhen(false)] string? s) | ||
| { | ||
| return string.IsNullOrWhiteSpace(s); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This is a shim on top of the <see cref="System.Diagnostics.Debug"/> class which adds attributes used | ||
| /// in nullability analysis. This is important because without the DoesNotReturnIf/DoesNotReturn attributes, | ||
| /// on Debug.Assert/Debug.Fail the C# compiler will see code like: | ||
| /// <code> | ||
| /// Debug.Assert(myArg != null, "Invalid argument") | ||
| /// </code> | ||
| /// And decide that because the code was attempting to handle 'myArg' being null, that it must be possible | ||
| /// for it to be null. | ||
| /// </summary> | ||
| [System.Diagnostics.DebuggerNonUserCode()] | ||
| public static class Debug | ||
| { | ||
| /// <summary> | ||
| /// Checks for a condition; if the condition is false, displays a message box that shows the call stack. | ||
| /// </summary> | ||
| /// <param name="condition">The conditional expression to evaluate. If the condition is true, a failure message is not sent and the message box is not displayed.</param> | ||
| [Conditional("DEBUG")] | ||
| public static void Assert([DoesNotReturnIf(false)] bool condition) | ||
| { | ||
| SysDebug.Assert(condition); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Checks for a condition; if the condition is false, outputs a specified message and displays a message box that shows the call stack. | ||
| /// </summary> | ||
| /// <param name="condition">The conditional expression to evaluate. If the condition is true, the specified message is not sent and the message box is not displayed.</param> | ||
| /// <param name="message">The message to send to the <see cref="System.Diagnostics.Trace.Listeners"/> collection.</param> | ||
| [Conditional("DEBUG")] | ||
| public static void Assert([DoesNotReturnIf(false)] bool condition, string message) | ||
| { | ||
| SysDebug.Assert(condition, message); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Checks for a condition; if the condition is false, outputs two specified messages and displays a message box that shows the call stack. | ||
| /// </summary> | ||
| /// <param name="condition">The conditional expression to evaluate. If the condition is true, the specified messages are not sent and the message box is not displayed.</param> | ||
| /// <param name="message">The message to send to the <see cref="System.Diagnostics.Trace.Listeners"/> collection.</param> | ||
| /// <param name="detailMessage">The detailed message to send to the <see cref="System.Diagnostics.Trace.Listeners"/> collection.</param> | ||
| [Conditional("DEBUG")] | ||
| public static void Assert([DoesNotReturnIf(false)] bool condition, string message, string detailMessage) | ||
| { | ||
| SysDebug.Assert(condition, message, detailMessage); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Emits the specified error message. | ||
| /// </summary> | ||
| /// <param name="message">A message to emit.</param> | ||
| [Conditional("DEBUG")] | ||
| [DoesNotReturn] | ||
| public static void Fail(string message) | ||
| { | ||
| SysDebug.Fail(message); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Emits an error message and a detailed error message. | ||
| /// </summary> | ||
| /// <param name="message">A message to emit.</param> | ||
| /// <param name="detailMessage">A detailed message to emit.</param> | ||
| [Conditional("DEBUG")] | ||
| [DoesNotReturn] | ||
| public static void Fail(string message, string detailMessage) | ||
| { | ||
| SysDebug.Fail(message, detailMessage); | ||
| } | ||
|
gregg-miskelly marked this conversation as resolved.
|
||
|
|
||
| /// <summary> | ||
| /// Writes a message followed by a line terminator to the debugger. | ||
| /// </summary> | ||
| /// <param name="message">A message to write.</param> | ||
| [Conditional("DEBUG")] | ||
| public static void WriteLine(string message) | ||
| { | ||
| SysDebug.WriteLine(message); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Writes the value of the object's <see cref="object.ToString"/> method to the debugger. | ||
| /// </summary> | ||
| /// <param name="value">An object whose value is sent to the debugger.</param> | ||
| [Conditional("DEBUG")] | ||
| public static void WriteLine(object value) | ||
| { | ||
| SysDebug.WriteLine(value); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Writes a category name and message to the debugger. | ||
| /// </summary> | ||
| /// <param name="message">A message to write.</param> | ||
| /// <param name="category">A category name used to organize the output.</param> | ||
| [Conditional("DEBUG")] | ||
| public static void WriteLine(string message, string category) | ||
| { | ||
| SysDebug.WriteLine(message, category); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Writes a category name and the value of the object's <see cref="object.ToString"/> method to the debugger. | ||
| /// </summary> | ||
| /// <param name="value">An object whose value is sent to the debugger.</param> | ||
| /// <param name="category">A category name used to organize the output.</param> | ||
| [Conditional("DEBUG")] | ||
| public static void WriteLine(object value, string category) | ||
| { | ||
| SysDebug.WriteLine(value, category); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.