Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[msh] Calling a .NET method with an 'out' parameter

1 view
Skip to first unread message

forestial

unread,
Mar 31, 2006, 6:31:01 PM3/31/06
to
I have a .NET object which supports a method with the signature

void getTags ( System.Int32 maxSel, out System.Collections.ArrayList
sourceTagIds )

What is the correct syntax for calling this in MSH? I tried

$tagIDs = new-object System.Collections.ArrayList
$tagSel.getTags(10, $tagIDs)

which gets the error
Cannot convert argument "1", with value: "", for "getTags" to type
"System.Collections.ArrayList&": "Cannot convert
"System.Collections.ArrayList" to "System.Collections.ArrayList&"."

This method expects the caller (my MSH script here) to allocate the
ArrayList object and pass it in (by reference) to be filled, and then passed
back.


Marcel Ortiz [MSFT]

unread,
Mar 31, 2006, 7:24:00 PM3/31/06
to
The current drop does not support out parameters. If you really need them,
at this point you would have to work around it using reflection.

--
Marcel Ortiz [MSFT]
Monad: Microsoft Command Shell
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"forestial" <fore...@discussions.microsoft.com> wrote in message
news:017DE62C-F4EA-4F1F...@microsoft.com...

forestial

unread,
Apr 3, 2006, 10:30:02 AM4/3/06
to
Thanks.

By "current drop does not support..." do you mean that it's not in the
current version of the beta, or that it will not be in the production release?

I haven't used Reflection much so I'm doing some reading on it to try to
follow your suggestion... is this something I can do in MSH or would I need
to wrap some C# code around the method in question"?

Jouko Kynsijärvi

unread,
Apr 3, 2006, 11:25:56 AM4/3/06
to
forestial wrote:
> I haven't used Reflection much so I'm doing some reading on it to try
> to follow your suggestion... is this something I can do in MSH or
> would I need to wrap some C# code around the method in question"?

You can call the "void getTags ( System.Int32 maxSel, out
System.Collections.ArrayList sourceTagIds )" method in MSH by using
Reflection as follows:

$tagSel = new-object ...
$params = 10, $null
$tagSel.GetType().InvokeMember('getTags', 'Instance,Public,InvokeMethod',
$null, $tagSel, $params)

After that $params[1] contains the returned ArrayList.


forestial

unread,
Apr 3, 2006, 12:19:01 PM4/3/06
to
Thanks: that certainly works.

I hope MSH is going to support this natively soon. While the reflection
technique seems extremely powerful at covering up all kinds of omissions,
it's certainly not the easiest to use....

Jeff Jones [MSFT]

unread,
Apr 3, 2006, 12:37:50 PM4/3/06
to
In the next drop you will be able to use a [ref] type for the parameter
which will allow the out parameter value to set as expected but you will
have to reference the .Value property of the parameter to get it. It will
be something like:

$tagIDs = new-object System.Collections.ArrayList
$tagSel.getTags(10, [ref]$tagIDs)

--
Jeff Jones [MSFT]
Monad Development


Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

"forestial" <fore...@discussions.microsoft.com> wrote in message
news:D5A072FA-2760-4DF8...@microsoft.com...

DBMwS

unread,
Apr 3, 2006, 1:55:41 PM4/3/06
to
> In the next drop
Do you mean the next Beta version or v2.0?

If it's going to show up in the next beta drop. it would be awesome! ;)

Jeff Jones [MSFT]

unread,
Apr 7, 2006, 11:59:04 AM4/7/06
to
It will be in the next beta version.

--
Jeff Jones [MSFT]
Monad Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

"DBMwS" <DontBother...@gmail.com> wrote in message
news:1144086941.8...@u72g2000cwu.googlegroups.com...

0 new messages