Comments (17)
Is the goal for this to be able to compare both objects by property value equality instead of by reference? I was planning on picking this one up, but saw that the Equals() stuff were using ReferenceEquals() so just want to make sure the plan was to switch to value comparisons since that's what record will do by default (for value types).
from activitypubsharp.
@warriordog No problem! And sure. I'll try doing some more research as well to see if there are any better alternatives. The gist seems decent but it would add some bloat 😅
from activitypubsharp.
Sure that should work!
from activitypubsharp.
I am happy to take this but I may not have the time to get to it until next week. If you have the bandwidth to take it before then then you can feel free to!
from activitypubsharp.
@CreggHancock sounds good! I may do it before then depending on my schedule this week. I'm getting very close to completing Project 1 (AS extensions) and this is a part of that.
from activitypubsharp.
Done. This should be the last thing before merging extensions support
from activitypubsharp.
@CreggHancock Yes, that's the intent. These are meant to be immutable and unique, so giving them value equality allows them to be used with HashSet and Dictionary without any duplication. Thanks for confirming!
from activitypubsharp.
Yep totally makes sense! I still feel like we'll run into an issue with the dictionary in JsonLDContextObject with it being a reference type. Some quick investigation shows it's trying to compare equality with reference type properties by reference even after JsonLDContextObject has been converted to a record.
I have found some possible solutions to this, like rolling out your own dictionary class that handles value comparison for equality. An example is in this gist. If that's a route you'd like to go down I'm happy to implement that.
from activitypubsharp.
@CreggHancock sorry, I totally missed your last comment! Thank you for bringing that up. Let me do some thinking and I'll get back to you.
from activitypubsharp.
@CreggHancock Do other collections, like List<T>
, work for value equality? I just realized that the list of contexts is small enough that we can probably do a naive linear search with no noticeable performance impact.
from activitypubsharp.
@CreggHancock Related, we could probably just implement a basic linked list for this. I've never seen a real-world object with more than 5 context entries, or more than 15 key/value pairs in a single object.
from activitypubsharp.
@warriordog Yeah if we implement our own list that overrides List that we can use throughout the project and it implements its own equality contract that is value based, that would solve the issue.
from activitypubsharp.
@CreggHancock we should only need to use it in the context types, right? We don't want everything to be value-typed.
from activitypubsharp.
Sure! The intention would be to use it for comparing these record types. I just meant it could be used throughout the project if we need value based comparisons. If we don't want that I can just implement it as an internal class though
from activitypubsharp.
@CreggHancock do you think we would need this anywhere else? I can't think of any other place that needs to compare a list by value equality.
from activitypubsharp.
@CreggHancock I think the best option to to implement a custom collection. For safety, I think it should not be generic and instead be hardcoded to only the exact case we need (IReadOnlyDictionary<string, JsonLDTerm>
). Otherwise, someone could accidentally use it with a mutable type. What do you think?
from activitypubsharp.
@CreggHancock just to clarify - did you want to pick up this work, or should I go ahead and do it?
from activitypubsharp.
Related Issues (20)
- Deserialize entities without a type name
- Rename functions and documentation to reflect new "model" naming
- Implement JSON-LD context use cases HOT 1
- Model implementations depend on internal `TypeMap.AddEntity`
- Include XMLDocs in the documentation build
- Expose DeserializationMetadata to anonymous / nameless entites
- Collection objects erroneously serialize as arrays
- Use the "new" generic pivots in IgnoreEmptyCollectionsModifier
- Determine whether JsonLDContextConverter can be removed
- No support for `content` property - only `contentMap` works
- JSON-LD context is not passed to nested objects HOT 6
- Prototype lazy type graphs HOT 1
- Get object's type string after deserialization HOT 3
- Rename `ActorEndpoints` to `APActorEndpoints` and move to separate file
- QuestionActivity: `Closed` and `ClosedAt` properties are totally broken HOT 1
- Internal unit tests do not run
- Hide `QuestionActivityEntity.OneOf` and `QuestionActivityEntity.AnyOf`
- NuGet snapshot workflow fails exactly 10% of the time HOT 1
- Support `object` and `link` values for `Question.closed`
- Link to roadmap from main readme file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from activitypubsharp.