-
-
Save annelo-msft/73d14d238ecc61ddb287894067469598 to your computer and use it in GitHub Desktop.
This file contains 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
// See https://aka.ms/new-console-template for more information | |
Console.WriteLine("Hello, World!"); | |
AzureCorePolicy azureCorePolicy = new AzureCorePolicy(); | |
ClientModelPolicy clientModelPolicy = new ClientModelPolicy(); | |
MockResponse response = new MockResponse(); | |
azureCorePolicy.SetIsError(response); | |
clientModelPolicy.UseIsError(response); | |
public class PipelineResponse | |
{ | |
public bool IsError | |
{ | |
get; | |
protected set; | |
} | |
} | |
public class Response : PipelineResponse | |
{ | |
// The key observation is that if you make the base type member virtual and remove this property | |
// the problem goes away. | |
public new virtual bool IsError | |
{ | |
get => base.IsError; | |
internal set => base.IsError = value; | |
} | |
} | |
public class MockResponse : Response | |
{ | |
private bool? _isError; | |
public override bool IsError { get => _isError ?? base.IsError; } | |
public void SetIsError(bool value) => _isError = value; | |
} | |
public class AzureCorePolicy | |
{ | |
public void SetIsError(MockResponse response) | |
{ | |
response.SetIsError(true); | |
Console.WriteLine($"AzureCorePolicy, Response.IsError: {response.IsError}"); | |
} | |
} | |
public class ClientModelPolicy | |
{ | |
public void UseIsError(PipelineResponse response) | |
{ | |
Console.WriteLine($"ClientModelPolicy, PipelineResponse.IsError: {response.IsError}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment