Re: Typed List
- From: Stefan Simek <simek.nospam@xxxxxxxxxxxxxxxxx>
- Date: Sun, 25 Dec 2005 18:48:03 +0100
I'd just recommend - reverse the implementation so that the explicit interface method calls the public method. In this special case you'll avoid boxing/unboxing, but IMHO, the public implementation should be primary and the explicit interface implementation should only adapt the interface method signature to the actual implementation.
interface IMyInterface {
void Function(object o);
}class MyClass : IMyInterface {
// explicit implementation (hidden)
void IMyInterface.Function(object o) {
// call the public typed implementation
Function((int) o);
} // own, typed implementation
public void Function(int i) {
// ... do something with i
}
}Just my 2c Stefan
Markus Stoeger wrote:
MuZZy wrote:
And the same question about IEnumerator implementation - what should i do so that "Current" would return a typed object of type "MyType", not of type 'object'?
Lookup "explicit interface implementation". It allows you to "hide" the untyped interface members and implement typed ones instead. Thats what the collection classes do too.
interface IMyInterface { void Function(object o); }
class MyClass : IMyInterface { // explicit implementation (hidden) void IMyInterface.Function(object o) { // ... do something with o }
// own, typed implementation public void Function(int o) { // call the exlicitely implemented function ((IMyInterface)this).Function(o); } }
Now if you have an instance of MyClass you'll only see the typed function "Function" with the int parameter. The untyped function is hidden (.. or only accessible when you cast the object to IMyInterface).
hth, Max
.
- References:
- Typed List
- From: MuZZy
- Re: Typed List
- From: MuZZy
- Re: Typed List
- From: Markus Stoeger
- Typed List
- Prev by Date: How to set all numericupdown auto-select text when got focus?
- Next by Date: Re: Typed List
- Previous by thread: Re: Typed List
- Next by thread: Re: Typed List
- Index(es):
Relevant Pages
|