I know this, but it is not useful.
I want to expose a class that implements IDictionary - I do not have a
choice on the interface. IDictionary implements IEnumerable
So in my example I showed trying to use the standard map class (which
implements IDictionary) this does not work.
Hi
Thanks for your quickly reply!
We need to implment the IDictionaryEnumerator and IDictionary.
Also we need to expose the GetEnumerator method so that it can support
Enumerate.
[DispId(-4)]
[return:
MarshalAs(UnmanagedType.CustomMarshaler,MarshalType="System.Runtime.InteropS
ervices.CustomMarshalers.EnumeratorToEnumVariantMarshaler,CustomMarshalers,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public IDictionaryEnumerator GetEnumerator()
Also we need to return a public class in the current property which will
return a public class.
public class DirEnt
public object Current
{
get
{
// TODO: Add ColCls.Current getter implementation
DictionaryEntry de = this.Entry;
return new DirEnt(de.Key,de.Value);
}
}
Here is the whole code snippet.
We can call in the vbscript as below.
dim o
dim objs
set objs = CreateObject("TestCo1.ColCls")
objs("a")="Hello"
objs("b")="World"
for each o in objs
WScript.Echo o.Key
WScript.Echo o.Value
next
using System;
using System.Collections;
using System.Runtime.InteropServices;
namespace TestCo1
{
public class DirEnt
{
private object _key;
private object _value;
public DirEnt()
{
}
public DirEnt(object k,object v)
{
_key=k;
_value = v;
}
public object Key
{
get {return _key;}
set {_key=value;}
}
public object Value
{
get {return _value;}
set {_value=value;}
}
}
public class ColCls :IDictionaryEnumerator,IDictionary
{
private Hashtable ht = new Hashtable();
IDictionaryEnumerator ide=null;
public ColCls()
{
}
#region IDictionary Members
public bool IsReadOnly
{
get
{
// TODO: Add ColCls.IsReadOnly getter implementation
return ht.IsReadOnly;
}
}
[DispId(-4)]
[return:
MarshalAs(UnmanagedType.CustomMarshaler,MarshalType="System.Runtime.InteropS
ervices.CustomMarshalers.EnumeratorToEnumVariantMarshaler,CustomMarshalers,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public IDictionaryEnumerator GetEnumerator()
{
// TODO: Add ColCls.GetEnumerator implementation
System.Diagnostics.Debug.WriteLine("public IDictionaryEnumerator
GetEnumerator()");
ide = ht.GetEnumerator();
return (IDictionaryEnumerator)this;
}
public object this[object key]
{
get
{
// TODO: Add ColCls.this getter implementation
return ht[key];
}
set
{
// TODO: Add ColCls.this setter implementation
ht[key]=value;
}
}
public void Remove(object key)
{
// TODO: Add ColCls.Remove implementation
ht.Remove(key);
}
public bool Contains(object key)
{
// TODO: Add ColCls.Contains implementation
return ht.Contains(key);
}
public void Clear()
{
// TODO: Add ColCls.Clear implementation
ht.Clear();
}
public ICollection Values
{
get
{
// TODO: Add ColCls.Values getter implementation
return ht.Values;
}
}
public void Add(object key, object value)
{
// TODO: Add ColCls.Add implementation
ht.Add(key,value);
}
public ICollection Keys
{
get
{
// TODO: Add ColCls.Keys getter implementation
return ht.Keys;
}
}
public bool IsFixedSize
{
get
{
// TODO: Add ColCls.IsFixedSize getter implementation
return ht.IsFixedSize;
}
}
#endregion
#region ICollection Members
public bool IsSynchronized
{
get
{
// TODO: Add ColCls.IsSynchronized getter implementation
return ht.IsSynchronized;
}
}
public int Count
{
get
{
// TODO: Add ColCls.Count getter implementation
return ht.Count;
}
}
public void CopyTo(Array array, int index)
{
// TODO: Add ColCls.CopyTo implementation
ht.CopyTo(array,index);
}
public object SyncRoot
{
get
{
// TODO: Add ColCls.SyncRoot getter implementation
return ht.SyncRoot;
}
}
#endregion
#region IEnumerable Members
IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
// TODO: Add ColCls.System.Collections.IEnumerable.GetEnumerator
implementation
System.Diagnostics.Debug.WriteLine("IEnumerator
System.Collections.IEnumerable.GetEnumerator()");
return this;//ht.GetEnumerator();
}
#endregion
#region IEnumerator Members
public void Reset()
{
// TODO: Add ColCls.Reset implementation
ide.Reset();
}
public object Current
{
get
{
// TODO: Add ColCls.Current getter implementation
DictionaryEntry de = this.Entry;
return new DirEnt(de.Key,de.Value);
}
}
public bool MoveNext()
{
// TODO: Add ColCls.MoveNext implementation
return ide.MoveNext();
}
#endregion
#region IDictionaryEnumerator Members
public object Key
{
get
{
// TODO: Add ColCls.Key getter implementation
return this.Key;
}
}
public object Value
{
get
{
// TODO: Add ColCls.Value getter implementation
return this.Value;
}
}
public DictionaryEntry Entry
{
get
{
// TODO: Add ColCls.Entry getter implementation
return ide.Entry;
}
}
#endregion
}
}
Best regards,
Perter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.