I just want to bind one collection to another one:
Lets say there is a
List<string> original = new List<string>();
and there is a
List<string> extended =
new List<string>(from curItem in originals select curItem + "_extension");
So the items of the extended are just the same than the original’s but with an “_extension” at the end.
What I want is to bind the extended to the original, so that if the original becomes changed, the extended also changes.
I know I could use events and recreate the extended every time.
But I think this is not efficient.
Edit:
Lets say: original is large and it is too exhausting to recreate the single elements of the extended and its also exhausting to create a single element at all.
So I want to have two lists (or collections) where on observes the other one and adds or removes the changes, like the data binding in Wpf, but adding an extension.
You can use the
BindingList<T>class on System.ComponentModel to achieve this… maybe it’s like killing a fly with a hammer, but will serve to more complex examples.I think you can make an extension method like this:
And you can use this on every
IEnumerable<String>: