Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Using __NewEnum in C#

I have managed to get the following to work

using System;
using System.Collections;
using AvstarNRCSLib;
class NRCS
{
static void Main()
{
Console.WriteLine("Hello, World");
ISignon signon = (ISignon)new __AnSignon();
signon.Signon("avstar", "avstar", "172.27.18.77", "", "");
if (signon.IsSignon() != 0)
{
Console.WriteLine("Signed on!");
IDirectory dir = (IDirectory)signon.get_Directory(".");
IEnumerable ite = (IEnumerable)dir;
foreach(Object item in ite) {
Console.WriteLine(item);
}
signon.Signoff();
}
else
{
Console.WriteLine("Error signing on!");
}
}
}

The problem is that I would like to call a method on the 'item' in the
foreach. Right now I just get System.__ComObject on the console. The
'directory' that is being enumerated returns an a list of VARIANTs
containing IDispatch. Each IDispatch contains common methods/properties such
as 'Name' and 'Type' which return strings. How do I call those
methods/properties?

Kevin Burton
kevin.burton@inewsroom.com
[1159 byte] By [Kevin Burton] at [2007-11-9 18:22:29]
# 1 Re: Using __NewEnum in C#
FYI. I find if I use

if(item is IDirectory)

Then I can cast item to an IDirectory interface and use its methods. This
seems to be the solution for me.

Kevin

"Kevin Burton" <kevin.burton@avstarnews.com> wrote in message
news:39d5054b$1@news.dev-archive.com...
> I have managed to get the following to work
>
> using System;
> using System.Collections;
> using AvstarNRCSLib;
> class NRCS
> {
> static void Main()
> {
> Console.WriteLine("Hello, World");
> ISignon signon = (ISignon)new __AnSignon();
> signon.Signon("avstar", "avstar", "172.27.18.77", "", "");
> if (signon.IsSignon() != 0)
> {
> Console.WriteLine("Signed on!");
> IDirectory dir = (IDirectory)signon.get_Directory(".");
> IEnumerable ite = (IEnumerable)dir;
> foreach(Object item in ite) {
> Console.WriteLine(item);
> }
> signon.Signoff();
> }
> else
> {
> Console.WriteLine("Error signing on!");
> }
> }
> }
>
>
> The problem is that I would like to call a method on the 'item' in the
> foreach. Right now I just get System.__ComObject on the console. The
> 'directory' that is being enumerated returns an a list of VARIANTs
> containing IDispatch. Each IDispatch contains common methods/properties
such
> as 'Name' and 'Type' which return strings. How do I call those
> methods/properties?
>
> Kevin Burton
> kevin.burton@inewsroom.com
>
>
Kevin Burton at 2007-11-11 22:27:38 >