Interface and collections

  • Thread starter Thread starter Lee
  • Start date Start date
L

Lee

Assuming I have an interface defined:

public interface IDTPersistableCollection: IList<IDTPersistableObject>
{
//Few specific properties defined

}

When I try to create an object based on this, I get all kind of errors
about members not being implemented such as this one:

Error 3 'AbstrationTestApp.Classes.CollectionBasic' does not implement
interface member
'System.Collections.Generic.IList<DTAbstraction.Interfaces.IDTPersistabl
eObject>.RemoveAt(int)'

I understand that I have to implement the required members of the
interface I'm implmementing. But, because I am using an interface, I
don't understand what it's asking for. I try to implement the RemoveAt
method, but still get errors.

Is there another trick to implementing collections using interfaces
that I am missing?

If figure 4 hours of trying to figure it out without success warrants a
post for help, LOL.

Thanks for any help,

--
Warm Regards,
Lee

"Upon further investigation it appears that your software is missing
just one thing. It definitely needs more cow bell..."
 
If you are using the IDE, the trick is to get VS to stub it out for you; in
2003 you can do this involving [Tab] and some luck; in 2005 you right-click
on the interface and choose "implement" (choosing explicit etc as you like).

I ran your code through this, and it gives me the following; plenty to fill
in ;-p

Marc

public interface IDTPersistableObject { }
public interface IDTPersistableCollection : IList<IDTPersistableObject>
{
void SomeOtherMethod(int param);

}
public class MyClass : IDTPersistableCollection {

public void SomeOtherMethod(int param) {
throw new Exception("The method or operation is not
implemented.");
}
public int IndexOf(IDTPersistableObject item) {
throw new Exception("The method or operation is not
implemented.");
}
public void Insert(int index, IDTPersistableObject item) {
throw new Exception("The method or operation is not
implemented.");
}
public void RemoveAt(int index) {
throw new Exception("The method or operation is not
implemented.");
}
public IDTPersistableObject this[int index] {
get {
throw new Exception("The method or operation is not
implemented.");
}
set {
throw new Exception("The method or operation is not
implemented.");
}
}
public void Add(IDTPersistableObject item) {
throw new Exception("The method or operation is not
implemented.");
}
public void Clear() {
throw new Exception("The method or operation is not
implemented.");
}
public bool Contains(IDTPersistableObject item) {
throw new Exception("The method or operation is not
implemented.");
}
public void CopyTo(IDTPersistableObject[] array, int arrayIndex) {
throw new Exception("The method or operation is not
implemented.");
}
public int Count {
get { throw new Exception("The method or operation is not
implemented."); }
}
public bool IsReadOnly {
get { throw new Exception("The method or operation is not
implemented."); }
}
public bool Remove(IDTPersistableObject item) {
throw new Exception("The method or operation is not
implemented.");
}
public IEnumerator<IDTPersistableObject> GetEnumerator() {
throw new Exception("The method or operation is not
implemented.");
}
System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator() {
throw new Exception("The method or operation is not
implemented.");
}
}
 
Marc Gravell enlightened me by writing:
If you are using the IDE, the trick is to get VS to stub it out for
you; in 2003 you can do this involving [Tab] and some luck; in 2005
you right-click on the interface and choose "implement" (choosing
explicit etc as you like).

I ran your code through this, and it gives me the following; plenty
to fill in ;-p

Marc

Thanks for the info. I was confused because I thought I only had to
implment the Ilist specific members, but as it turns out, logically I
have to include ICollection members as well.

Thanks again,

--
Warm Regards,
Lee

"Upon further investigation it appears that your software is missing
just one thing. It definitely needs more cow bell..."
 
Back
Top