does anyone know of a way that I can implement basically a custom queryinterface, for example:
In some Class Library
public interface ICollectionItem
{
...
}
public class MyCollection: System.Collections.CollectionBase
{
...
public int Add(ICollectionItem Item)
{
return List.Add(Item);
}
}
public interface IMyService
{
string ImplementedBy;
}
public class MyService: ICollectionItem, IMyService
{
...
public string ImplementedBy()
{
return "MyService";
}
}
somewhere in the asp.net application code
...
MyCollection myCollection = new MyCollection();
MyCollection.Add(new MyService);
...
//now this is what I would like to work...
if (MyCollection is IMyService)
{
Label1.Text = (IMyService)MyCollection.ImplementedBy()
}
In Delphi (I am still a little new to C#), I used to do this by overriding the QueryInterface method in the MyCollection. I would override it so that would it would return the first item in the list that implements the Interface. Is there a way to do something like this in C#?