azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

Make JsonData Immutable

Open annelo-msft opened this issue 3 years ago • 1 comments
trafficstars

Modifications to JsonData by @jsquire.

Addresses https://github.com/Azure/azure-sdk-for-net/issues/30717

annelo-msft avatar Sep 16 '22 16:09 annelo-msft

API change check

APIView has identified API level changes in this PR and created following API reviews.

Azure.Core.Experimental

azure-sdk avatar Sep 16 '22 16:09 azure-sdk

@jsquire, do you know why we implement IDynamicMetaObjectProvider instead of inheriting from DynamicObject?

I do not. @ellismg would probably have insight.

jsquire avatar Sep 30 '22 19:09 jsquire

I do not. @ellismg would probably have insight.

I can't recall the exact reason, but if I had to hazard a guess, it would be that we didn't want to inherit all of the public methods from DynamicObject on to our public surface area and into intellisense. Suspect that's also why we decided to explicitly implement the interface.

ellismg avatar Sep 30 '22 20:09 ellismg

I can't recall the exact reason, but if I had to hazard a guess, it would be that we didn't want to inherit all of the public methods from DynamicObject on to our public surface area and into intellisense. Suspect that's also why we decided to explicitly implement the interface.

We're investigating making the JsonData API fully internal, so I revisited this question.

It looks like all the TryXx methods on DynamicObject only get called after an attempt to access the dynamic property/conversion/method etc on the underlying typed instance fails and throws an exception, which would degrade performance. So, I think we will still want to implement IDynamicMetaObjectProvider even if the API is internal.

There's also the following comment in the DynamicObject reference docs, supporting this hypothesis:

if you need to manage DLR fast dynamic dispatch caching, create your own implementation of the IDynamicMetaObjectProvider interface.

See: https://learn.microsoft.com/en-us/dotnet/api/system.dynamic.dynamicobject?view=net-7.0#remarks

annelo-msft avatar Oct 24 '22 18:10 annelo-msft

Closing in favor of https://github.com/Azure/azure-sdk-for-net/pull/31769

annelo-msft avatar Oct 24 '22 19:10 annelo-msft