You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class Response
{
public HttpStatusCode StatusCode => Error?.StatusCode ?? SuccessStatus;
public Error Error { get; }
private HttpStatusCode SuccessStatus { get; }
protected Response(Error error)
{
Error = error;
}
protected Response()
{
SuccessStatus = HttpStatusCode.OK;
}
protected Response(HttpStatusCode statusCode)
{
SuccessStatus = statusCode;
}
public static Response<T> Result<T>(T value)
=> new Response<T>(value);
public static Response<T> Result<T>(T value, HttpStatusCode successStatus)
=> new Response<T>(value, successStatus);
public bool IsError => (int)StatusCode > 299;
public override string ToString()
{
return new
{
StatusCode,
Error,
}.ToString();
}
public static implicit operator Response(Error error) => new Response(error);
}
And Error is:
public sealed class Error : CommunicationErrorResponse, IEquatable<Error>
{
public HttpStatusCode StatusCode { get; }
public Error(HttpStatusCode statusCode, CommunicationError response , TimeSpan? retryAfter , string wwAuthenticateHeaderValuel)
{
StatusCode = statusCode;
Error = response;
RetryAfter = retryAfter;
_wwwAuthenticateHeaderValue = wwwAuthenticateHeaderValue;
}
public bool Equals(Error other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return StatusCode == other.StatusCode
&& RetryAfter.Equals(other.RetryAfter)
&& Equals(Error, other.Error);
}
public bool Equals(Error other, bool strict)
{
if (strict)
{
return Equals(other);
}
return StatusCode == other?.StatusCode
&& Error.Code == other.Error.Code
&& Error.Message == other.Error.Message;
}
public override bool Equals(object obj)
{
if (obj is Response response)
{
return Equals(response.Error);
}
return ReferenceEquals(this, obj) || Equals(obj as Error);
}
public override int GetHashCode()
{
return HashCode.Combine((int)StatusCode, RetryAfter, Error);
}
}
And CommunicationErrorResponse is:
public class CommunicationErrorResponse
{
/// <summary>
/// The Communication Services error.
/// </summary>
[SwaggerRequired]
public CommunicationError Error { get; set; }
}
The text was updated successfully, but these errors were encountered:
However, the Analyzer assumes that Equal(object?) tests against instance of the type defining the method not possible other types. The Analyzer has no access to your implementation to see what other types it allows comparing with.
In initially though you could add a reciprocal implicit conversion to Response (and drop the test on Response in Error.Equals(object?):
@alexandra142 I think that it would work if Error is implementing IEquatable<Result> as the Analyzer (like NUnit) looks for implementation of where actualType implement IEquatable<_expectedType_> and vice versa.
Hello,
I am writing to notify you that your analyzer mark a code as not compatible types for EqualTo, but it is not true .
for code:
Assert.That(result, Is.EqualTo(Error.EntraAssignmentNotFound));
Where result is type of Response :
And Error is:
And CommunicationErrorResponse is:
The text was updated successfully, but these errors were encountered: