Skip to content

Instantly share code, notes, and snippets.

@annelo-msft
Last active January 5, 2024 18:20
Show Gist options
  • Save annelo-msft/73d14d238ecc61ddb287894067469598 to your computer and use it in GitHub Desktop.
Save annelo-msft/73d14d238ecc61ddb287894067469598 to your computer and use it in GitHub Desktop.
// 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