473,237 Members | 1,220 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,237 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 5674
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.