Open sharwell opened 5 years ago
Chatting with @agocke about a similar issue earlier today (not this one though), it seems like the opinion might have been to just write SpecializedTasks.Default<string?>()
.
@jasonmalinowski If we could write the following, then your approach would be fairly ideal:
public static Task<T> Default<T>()
where T : defaultable
{
// ...
}
Currently we don't have a way to document the semantics of
SpecializedTasks.Default<T>
such that the compiler knows that the result is nullable for reference types. This issue is requesting support from the language team to understand the best pattern(s) to employ in cases like this.https://github.com/dotnet/roslyn/blob/98b82ec70a2d9e6953a588464bce44fa245182b3/src/Workspaces/Core/Portable/Utilities/SpecializedTasks.cs#L20-L23