471,594 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 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 5592
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Nick Keighley | last post: by
7 posts views Thread by R. Anbeeswaran | last post: by
6 posts views Thread by Jegger | last post: by
reply views Thread by Christopher Boomer | last post: by
8 posts views Thread by Mark | last post: by
8 posts views Thread by Brian P | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.