C#, VS2003, 1.1 Framework
I have a custom class implementation thats based on
System.Collections.CollectionBase.
I've implemented the Add, Remove, Contains, CopyTo etc... all the normal
stuff. This also has to be registered for COM Interop so classic ASP pages
can access it's properties and methods. Everything works, with the
exception of "Count" I've tried using the keyword "new" but that doesn't
help either. The error message begin returned is that the object doesn't
support the property or method "Count".
This one eludes me. I've tried just defining the Count property in the
Interface declaration, but that doesn't work either. I also wonder if
perhaps I could just implement ICollection instead.
Sample
[Guid("E9C924C6-540D-4b36-94DB-79B3244C9907")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ISimpleList
{
[DispId(1)]
int Add(object item);
[DispId(2)]
void Delete(object item);
[DispId(3)]
bool Contains(object item);
[DispId(4)]
void CopyTo(object[] array, int index);
[DispId(5)]
object this[int index]{get;}
[DispId(6)]
int Count{get;}
[DispId(7)]
IEnumerator GetEnumerator();
}
[Guid("E7231AC1-9215-42e3-B86E-7AA2FEDD4011")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("ssiAcres.SimpleList")]
public class SimpleList : System.Collections.CollectionBase, IEnumerable,
ICollection, ISimpleList
{
public SimpleList(){}
public int Add (object item)
{
return List.Add(item);
}
public void Delete (object item)
{
List.Remove(item);
}
public bool Contains(object item)
{
return List.Contains(item);
}
public void CopyTo(object[] array, int index)
{
List.CopyTo(array, index);
}
public object this[int index]
{
get{return (object)this.List[index];}
}
IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return List.GetEnumerator();
}
public int Count
{
get{return List.Count;}
}
}
Dave Young - 12 Mar 2007 22:43 GMT
Resolved
Rather than inherit from CollectionsBase, I just just wrote the ISimpleList
definition to implement IList, IEnumerable and ICollection. Then, I went
back and changed the class definition to implement ISimpleList instead.
That fixed it.
> C#, VS2003, 1.1 Framework
>
[quoted text clipped - 75 lines]
> }
> }