[Mono-list] Trouble accessing interface methods via as operator
Michal Moskal
malekith@pld-linux.org
Tue, 13 Apr 2004 10:02:18 +0200
On Tue, Apr 13, 2004 at 03:39:54AM -0400, Joe Scaduto wrote:
> Hello,
>
> I am trying to use the 'as' operator to access interface methods. I am
> using reflection to create an instance of the class which implements the
> interface. I am able to obtain the object but the 'as' operator always
> returns null for me even though the class does implement the interface.
> I am not sure what is going. Any help would be greatly appreciated.
>
> code snippet:
>
> System.Object obj = Activator.CreateInstance(type);
> IServices current = obj as IServices;
>
> if (current == null)
> Console.WriteLine("obj does not implement IServices");
Are you sure it is *the same* IServices that is implemented and that you
use on right hand side of 'as' ? Where does the type come from? And
where does the IServices come from? IServices seen by 'type' and 'as'
can be different even when they share the name.
--
: Michal Moskal :: http://www.kernel.pl/~malekith :: GCS !tv h e>+++ b++
: When in doubt, use brute force. -- Ken Thompson :: UL++++$ C++ E--- a?