473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Missing ReadOnlyDictionary<>?

So did the .NET 2.0 working group just run out of steam before it got to a
ReadOnlyDictionary<> wrapper?

I am publishing events containing a SortedList<>, and obviously I don't want
event handlers to be able to do anything to the collection at the same time
other recipients could be handling it.

I found a ReadOnlyCollection<> wrapper, which I can apply to the .Keys and
..Values of the SortedList, but I can't find any way to wrap the SortedList
itself. I need to preserve SortedList functionality, but I would prefer to
have a programmatic way of ensuring recipients don't manhandle the shared
SortedList.

Is there any other solution to that short of writing my own
ReadOnlyDictionary, or cloning the collection for every recipient (which is
prohibitively expensive for me)?
Jun 29 '06 #1
4 5683
Dave Booker <db******@newsgroup.nospam> wrote:
So did the .NET 2.0 working group just run out of steam before it got to a
ReadOnlyDictionary<> wrapper?
Dictionary<,> defines no virtual methods for speed reasons, so it's not
possible to create a ReadOnlyDictionary<,> which is replaceable with
Dictionary<,>. The best solution is to write one which implements
IDictionary<,>.

Personally, I think it would have been nice for them to provide a
read-only IDictionary<,> wrapper, but they didn't.

The rationale seems to be that Dictionary<,> and List<> are classes
useful for class implementation, but shouldn't be exposed to the outer
world, because they have too much public functionality, and so might
confuse inexperienced users. Apparently, the recommended way to expose
these as properties is via Collection<> or KeyedCollection<,>.
Is there any other solution to that short of writing my own
ReadOnlyDictionary, or cloning the collection for every recipient (which is
prohibitively expensive for me)?


I'd write a ReadOnlyDictionary wrapper, have it implement the same
interfaces as Dictionary<,>, and delegate non-mutable methods to the
underlying Dictionary<,>. Have the mutable operations throw
InvalidOperationException or something. Shouldn't take more than 5
minutes.

-- Barry

--
http://barrkel.blogspot.com/
Jun 29 '06 #2
Dear Customer,

Thanks for your great feedback that does to be a good idea.
I do understand your scenario, I highly suggest you can submit this
feedback to our product feedback center:
http://lab.msdn.microsoft.com/produc...k/default.aspx

Also based on my research, here are some links for your reference.

A read-only IDictionary wrapper for .Net 1/1.1
http://www.dotnetguru2.org/index.php...&c=1&tb=1&pb=1

http://www.koders.com/csharp/fidD617...FC835C6E6B.asp
x

Thanks for your understanding!

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 29 '06 #3
Thank you both for the tips.

BTW, looks like this issue was already sent to the Product Feedback center:
http://connect.microsoft.com/VisualS...edbackID=94358

Jun 29 '06 #4
Dear Customer,

Thanks for your mention.
I think our product team will evaluate the feedback.

Thanks for your understanding!

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 30 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Nick Keighley | last post by:
I'm probably missing something rather obvious, but is there a known problem with getting a Python based socket program to communicate with a C based socket program? A simple echo server written in...
7
by: R. Anbeeswaran | last post by:
Hi All, void main() { const int i = 20; int *p = const_cast<int*>(&i); *p = 40; cout <<"i="<< i <<"\t"<<"*p="<<*p<<"\n"; }
6
by: Jegger | last post by:
Hello! We have following situation; network with 100 users, aplication developed in Access, user DB deployed on SQL Server. Is it better to create query inside aplication (with code) and then...
0
by: Christopher Boomer | last post by:
I am relatively new to the world of XML and python, and I think I am still missing some of the basic concepts. It cannot be as hard as I think, or programmers would be flocking to it the way they...
8
by: Mark | last post by:
We have a multi-line textbox that users copy and paste email text into. The pasted text frequently will contain a tag like <blah@aol.com> or similar. I believe .NET is protecting itself from code...
8
by: Brian P | last post by:
I want to expose a property of Dictionary<string, MyAbstractClass>. I tried to do it this way: private Dictionary<string, MyChildClass> _dictionary; public Dictionary<string,...
3
by: Dave Booker | last post by:
Am I missing something here? It looks like the generic Queue<T> implements Enumerable<T> and ICollection but not ICollection<T>. (I want to use it in an interface that wants an ICollection<T>.) ...
4
by: Grizlyk | last post by:
Hello. Why were base class "typedefs" hidden by template<and explicit usage of them does not work too? Try open only one of the lines in the example below //using Tparent::Tptr; //typedef...
14
by: Michael | last post by:
Since the include function is called from within a PHP script, why does the included file have to identify itself as a PHP again by enclosing its code in <?php... <?> One would assume that the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.