The IDE tells me that the cast is redundant in here:
private EntityIdentifier(EntityIdentifierFlags flags, ReadOnlyMemory<byte> identifier, ReadOnlyMemory<byte> identifierSuffix, ReadOnlyMemory<byte>? buffer = null)
: base(buffer == null ? new Lazy<ReadOnlyMemory<byte>>(CreateMemoryFactory(flags, identifier, identifierSuffix)) : new Lazy<ReadOnlyMemory<byte>>((ReadOnlyMemory<byte>)buffer))
{
this.Flags = flags;
this.Identifier = identifier;
this.IdentifierSuffix = identifierSuffix;
}
(ReadOnlyMemory<byte>)buffer in new Lazy<ReadOnlyMemory<byte>>((ReadOnlyMemory<byte>)buffer) could be simplified to just buffer, because buffer is ReadOnlyMemory<byte>?. But upon simplification, the IDE cannot find the correct constructor to use. It complains that ReadOnlyMemory<byte>? cannot be converted to type bool.
This issue has been moved from https://developercommunity.visualstudio.com/content/problem/445486/ide-cannot-make-up-its-mind-cast-is-necessary-or-u.html
VSTS ticketId: 786138
These are the original issue comments:
I_Keon_Un on 2/5/2019, 08:14 AM (5 days ago): I solved it by writing an extension method for ReadOnlyMemory>:
static class ReadOnlyMemoryExtensions
{
public static Lazy> ToLazyReadOnlyMemory(this ReadOnlyMemory buffer) => new Lazy>(buffer);
}
And I rewrote my original constructor as follows:
private EntityIdentifier(EntityIdentifierFlags flags, ReadOnlyMemory identifier, ReadOnlyMemory identifierSuffix, ReadOnlyMemory? buffer = null)
: base(buffer?.ToLazyReadOnlyMemory() ?? new Lazy>(CreateMemoryFactory(flags, identifier, identifierSuffix)))
{
this.Flags = flags;
this.Identifier = identifier;
this.IdentifierSuffix = identifierSuffix;
}
That gets rid of the errors. But ideally, the method overload resolution should be smarter than that. And at the very least, the IDE should not be giving misleading advice.
I_Keon_Un on 2/5/2019, 08:15 AM (5 days ago): Oh god… what happened to the markdown formatting in my comment above…?
These are the original issue solutions:
(no solutions)
The IDE tells me that the cast is redundant in here:
(ReadOnlyMemory<byte>)bufferinnew Lazy<ReadOnlyMemory<byte>>((ReadOnlyMemory<byte>)buffer)could be simplified to justbuffer, becausebufferisReadOnlyMemory<byte>?. But upon simplification, the IDE cannot find the correct constructor to use. It complains thatReadOnlyMemory<byte>?cannot be converted to typebool.This issue has been moved from https://developercommunity.visualstudio.com/content/problem/445486/ide-cannot-make-up-its-mind-cast-is-necessary-or-u.html
VSTS ticketId: 786138
These are the original issue comments:
I_Keon_Un on 2/5/2019, 08:14 AM (5 days ago): I solved it by writing an extension method for
ReadOnlyMemory>:static class ReadOnlyMemoryExtensions
{
public static Lazy> ToLazyReadOnlyMemory(this ReadOnlyMemory buffer) => new Lazy>(buffer);
}
And I rewrote my original constructor as follows:
private EntityIdentifier(EntityIdentifierFlags flags, ReadOnlyMemory identifier, ReadOnlyMemory identifierSuffix, ReadOnlyMemory? buffer = null)
: base(buffer?.ToLazyReadOnlyMemory() ?? new Lazy>(CreateMemoryFactory(flags, identifier, identifierSuffix)))
{
this.Flags = flags;
this.Identifier = identifier;
this.IdentifierSuffix = identifierSuffix;
}
That gets rid of the errors. But ideally, the method overload resolution should be smarter than that. And at the very least, the IDE should not be giving misleading advice.
I_Keon_Un on 2/5/2019, 08:15 AM (5 days ago): Oh god… what happened to the markdown formatting in my comment above…?
These are the original issue solutions:
(no solutions)