views:

393

answers:

3

using: VS2008, C#

I have a COM dll I need to use in a .NET project. In there I have a class with a method that returns an IDictionary object. IDictionary is defined in the COM dll so I'm not sure if it's the same as IDictionary in .NET.

My problem: I know the dictionary keys and I want to retrieve the values. The documentation for this COM dll gives code in Classic ASP like

someValue = oMyDictionary.someDictionaryKey

My Question: How do I retrieve the values for the specific keys in C#?

When I create the IDictionary object in C# like this:

IDictionary oDictConfig = oAppConfig.GetOptionsDictionary("");

VS2008 reckons this dictionary object (interface) has the following methods and properties:

Cast<>
Count
Equals
GetEnumerator
GetHashCode
GetMultiple
GetType
let_Value
OfType<>
Prefix
PutMultiple
ToString

Sorry if this is a silly question, but I can't see how to retrieve a value passing a key.

A: 

IDictionary has an Item property among its members that you access via [ ].

var obj = oDictConfig[key];
tvanfosson
A: 

Try this:

dicObject["myKey"]
SirDemon
Great that worked. Thanks. Just needed to cast it as a string.
mattRo55
A: 

It looks like you are using the IDictionary COM interface from BizTalk Server 2000:

http://msdn.microsoft.com/en-us/library/ms936717.aspx

This interface should also have a NewEnum property (check the interop assembly in Reflector) which should return an IEnumerable to you. This IEnumerable will be an enumeration of the keys, which you can then use with calls to the Value property (with the appropriate key of course) to get the values.

casperOne