stewienj / swordfishcollections Goto Github PK
View Code? Open in Web Editor NEWC# library for Concurrent Observable Collection, Dictionary, and Sorted Dictionary
License: Creative Commons Zero v1.0 Universal
C# library for Concurrent Observable Collection, Dictionary, and Sorted Dictionary
License: Creative Commons Zero v1.0 Universal
Can't add this package to c++/clr projects, need to work out how, see
https://stackoverflow.com/questions/40893161/create-nuget-package-for-c-cli-mixed-assembly
https://stackoverflow.com/questions/18694947/how-can-i-make-my-managed-nuget-package-support-c-cli-projects
The overloads are listed here https://learn.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentdictionary-2.getoradd?view=net-7.0
Overloads
GetOrAdd(TKey, Func<TKey,TValue>) | Adds a key/value pair to the ConcurrentDictionary<TKey,TValue> by using the specified function if the key does not already exist. Returns the new value, or the existing value if the key exists. |
---|---|
GetOrAdd(TKey, TValue) | Adds a key/value pair to the ConcurrentDictionary<TKey,TValue> if the key does not already exist. Returns the new value, or the existing value if the key exists. |
GetOrAdd(TKey, Func<TKey,TArg,TValue>, TArg) | Adds a key/value pair to the ConcurrentDictionary<TKey,TValue> by using the specified function and an argument if the key does not already exist, or returns the existing value if the key exists. |
This should be NotifyCollectionChangedAction.Remove
, not NotifyCollectionChangedAction.Add
I use WPF in WinForms . Before , i used CollctionsV2 and modeified the DispathcerQueueProcesser.cs so that it can run in WinForms , but the the UI and backgroundwork often freeze . I can't figure out why it freeze. So i want to use ColltionsV3 , but i don't know how to modify it so that it can be used in WinFroms. Any idea?
ConcurrentObservableDictionary is not a straight wrapper around an ImmutableDictionary, instead it has a dual personality where it can be used as a Dictionary or a List. This behaviour stems from a very old requirement that has long been forgotten. Unfortunately this behaviour also has significant performance penalties. The ConcurrentObservableDictionary class should be moved to ConcurrentObservableDictionaryList, and a proper ConcurrentObservableDictionary should be created that works the same way as other classes list ConcurrentObservableHashSet.
This change will be a breaking change for anyone using ConcurrentObservableDictionary as a List. I'm wondering how many people this will affect?
use Reset() result is not sorted.
AddRange is no problem.
Hi,
I'm trying to use the AddRange
method of ConcurrentObservableDictionary
, but it always fail, due to a casting.
Unhandled exception. System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.String]' to type 'System.Collections.IList'.
at Swordfish.NET.Collections.ConcurrentObservableDictionary`2.<>c__DisplayClass4_0.<AddRange>b__2(Int32 index)
at Swordfish.NET.Collections.ConcurrentObservableBase`2.BodyReadWriteNotify[TRead](TRead readValue, Func`2 write, Func`2[] changes)
at Swordfish.NET.Collections.ConcurrentObservableBase`2.DoReadWriteNotify[TRead](Func`1 read, Func`2 write, Func`2[] changes)
at Swordfish.NET.Collections.ConcurrentObservableDictionary`2.AddRange(IEnumerable`1 pairs)
at MyMethodCallingAddRange() in /where/my/code/is.cs:line 42
I tried with some variant of a IDictionnary
(normal, default concurrent, concurrent from your library).
Temporary fix: I call AddRange
with a IList<KeyValuePair<string, string>>
Hi Awsome Library!
Is it possible to implement IEqualityComparer on both your HashSet and SortedSet Collections?
Thanks
Basically I'm using ConcurrentObservableCollection as a drop-in replacement for ObservableCollection, and was surprised that it doesn't provide constructors that take some kind of IEnumerable. This is mostly a nice to have that allows initializing code to be moved out of the constructor, like this:
public ConcurrentObservableCollection<int> MyCollection { get; init; } = new(new int[4]);
Hi @stewienj
Originally i bind a ConcurrentObservableDictionary to StackLayout and everything works good in a maui project. When I wanna to replace StackLayout with CollectionView. The binding fails with below error.
Can you guys take a look at and to see if anything i have missed. Thank you in advance.
Please refer to this repo for more details: https://github.com/WisJamison/Maui-CollectionView-Sample
With .NET 7.0 there are steps that can be taken to make a library Ahead Of Time compatible. See here https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/
As you are the dev it would be great to read why and how you have done this ... and maybe why.
Differences to BCL and so on.
So would be great to extend the readme a bit :)
Currently you can't directly bind to the CollectionView. Have a BindableCollectionView class. This wraps an immutable collection, fires INotifyCollectionChanged with a Reset action and gets the Synchronization context when it is created.
Hi guys,
This set of collections seems awesome. Any chance you will build them so they work in PCL Libraries? Would love to give them a try in Xamarin.Forms.
Thanks and keep up the great work.
Patrice
I would need a thread safe sorted set as a cache inside my asp.net app.
Want to get a set of objects based on an enumerable in a specific sort order.
This is an awesome library. Been using it for a year now so it feels right to contribute
INotifyPropertyChanged
to signal Count
changeConcurrentObservableCollection<MyObject> collection = GetSomeCollection();
Predicate<MyObject> predicate = GetSomePredicate();
lock (((System.Collections.ICollection)collection).SyncRoot)
{
if (collection.Any(i => predicate(i)))
collection.Add(GetMyObject());
}
This is something similar to ConcurrentDictionary.TryAdd()
I already did 2, 5 and part of 1 in my forked repo. Will put more work on it if people agree and consider them to be useful
Anybody have any ideas on how to get this collection type to play nicely with the ListCollectionView? Currently have a WPF ListView Binding to the CollectionView property of the collection, and creating a ListCollectionView to add live sorting and live filtering on via CollectionViewSource.GetDefaultView(MyCollection.CollectionView)
I would guess that since we are not actually binding to a collection, but rather to a property instead that the live filtering and sorting are not being applied.
I've tried catching the property changed event and manually calling ListCollectionView.Refresh() to no avail.
The directory and project structure needs to be tidied up a bit on this project.
There's a mix of some utility stuff in the Swordfish.NET project that is stored in the General directory.
Version 2 of Swordfish.NET.Collections is in the Collections directory.
Version 3 of Swordfish.NET.Collections is in the CollectionsV3 directory.
There's some examples and tests in the ExamplesAndTests directory.
Would be good to keep V3 of the Collections a Portable Class Library. So anything WPF specific should go into another library. Same with the utility stuff.
Will also need a Documentation directory.
Any major rearrangement should be timed to reduce disruption to branches that are in active development, e.g. the PCL branch being worked on by @fjch1997
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.