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

Remove class constraint on AsNonNull() #5296

Merged
merged 1 commit into from
Jul 6, 2022
Merged
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
7 changes: 2 additions & 5 deletions osu.Framework/Extensions/ObjectExtensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ public static class ObjectExtensions
/// <param name="obj">The nullable object.</param>
/// <typeparam name="T">The type of the object.</typeparam>
/// <returns>The non-nullable object corresponding to <paramref name="obj"/>.</returns>
public static T AsNonNull<T>(this T? obj)
where T : class
{
return obj!;
}
[return: NotNullIfNotNull("obj")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunate that the attribute requires literal string since nameof isn't supported on parameter names, there seem to be proposals about it as well (dotnet/csharplang#373 (comment)).

public static T AsNonNull<T>(this T? obj) => obj!;

/// <summary>
/// If the given object is null.
Expand Down