-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClientModel: Convince ourselves that the virtual
problem isn't a concern
#41234
Comments
I spent some time thinking about this. It seems to me like the most tricky case is a virtual get-set property on an existing subtype. For example, the Request.Uri property. It seems to me that we can make everything work correctly, if we: a) have just ome source of truth (a filed in the subclass), b) seal Core property/methods in the subclass. For example: public abstract class PipelineRequest
{
public Uri Uri {
get => UriCore;
set => UriCore = value;
}
protected abstract Uri UriCore { get; set; }
}
public abstract class Request : PipelineRequest
{
RequestUriBuilder? _uri;
public new virtual RequestUriBuilder Uri {
get => _uri ??= new RequestUriBuilder();
set => _uri = value;
}
protected sealed override Uri UriCore {
get => Uri.ToUri();
set => Uri.Reset(value);
}
}
public class RequestUriBuilder
{
public Uri ToUri() => throw new NotImplementedException();
public void Reset(Uri value) => throw new NotImplementedException();
} |
In the case of get-only properties (e.g. Response.Content) where the type of the property does not change in the subclass, we should do what the notes say, i.e. make the property virtual. In the case of get-only properties (e.g. Response.Content) where the type of the property does change in the subclass, we should do what the notes say, i.e. use protected Core method. |
Let's implement the combinations of the recommendations (from the table) and the one I added for get-set properties (Request.Uri). Hopefully these will cover all the cases. if you run into another case that is not discussed in the issue, let me know |
|
Could you link to adapter code that illustrates how the adapter overrides (or has to override) the UriCore property? |
I put a simplification of the problem as I understand it in this gist: The adapter implementation in the Azure.Core 2.0 integration PR branch is here:
|
Completed with #42010 |
At a high level
A simple description of how this problem works is described here: https://gist.github.com/annelo-msft/73d14d238ecc61ddb287894067469598
In our code base, I discovered this when:
a. IsError is set to true on MockResponse, but false on base PipelineResponse
Generalizing this:
Concerns I have as a result of this
Full API description of Request and Response types
The text was updated successfully, but these errors were encountered: