Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

ParameterSetName - How to handle multiple mutual exclusions

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 09-10-2006   #1 (permalink)
Keith Hill [MVP]
Guest


 

ParameterSetName - How to handle multiple mutual exclusions

What if I have multiple mutual excluions such as:

Path vs LiteralPath and Time vs FileWithTime where I need either Time or
FileTime to work in conjunction with either Path or LiteralPath. How do you
do that with the ParameterSetNameAttribute?

--
Keith



My System SpecsSystem Spec
Old 09-10-2006   #2 (permalink)
Alex K. Angelopoulos [MVP]
Guest


 

Re: ParameterSetName - How to handle multiple mutual exclusions

There's no direct native mechanism for handling complex usages like that.
This was one limitation the developers mentioned in private beta days.
Trying to represent it in Get-Command would get pretty complex as well,
since there are 4 distinct usage statements from that set.

The approach I've used is to refactor parameter sets like this.

Assuming this is your touch cmdlet, here's how I would probably approach it.
I would change this back to a single parameter Time, but make it an object.
If it is a filesystem object or a path to an object, you get the time from
the object's timestamp. If not, it's parsed as a time.

Frankly, I would also like to see them change the string[] LiteralPath to
just Switch Literal to modify the treatment of the Path parameter. That
makes syntax much simpler.

"Keith Hill [MVP]" <r_keith_hill@mailhot.moc.nospam> wrote in message
news:uRjXNiS1GHA.1040@TK2MSFTNGP06.phx.gbl...
> What if I have multiple mutual excluions such as:
>
> Path vs LiteralPath and Time vs FileWithTime where I need either Time or
> FileTime to work in conjunction with either Path or LiteralPath. How do
> you do that with the ParameterSetNameAttribute?
>
> --
> Keith
>



My System SpecsSystem Spec
Old 09-10-2006   #3 (permalink)
Keith Hill [MVP]
Guest


 

Re: ParameterSetName - How to handle multiple mutual exclusions


"Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
news:eTJc%23PT1GHA.1288@TK2MSFTNGP03.phx.gbl...
> There's no direct native mechanism for handling complex usages like that.
> This was one limitation the developers mentioned in private beta days.
> Trying to represent it in Get-Command would get pretty complex as well,
> since there are 4 distinct usage statements from that set.
>
> The approach I've used is to refactor parameter sets like this.
>
> Assuming this is your touch cmdlet, here's how I would probably approach
> it. I would change this back to a single parameter Time, but make it an
> object. If it is a filesystem object or a path to an object, you get the
> time from the object's timestamp. If not, it's parsed as a time.


I'll look into what I can do there. Basically I could accept an Object and
then hurl if it is not either a string that is a valid path to a file, a
FileInfo object or a DateTime object.

> Frankly, I would also like to see them change the string[] LiteralPath to
> just Switch Literal to modify the treatment of the Path parameter. That
> makes syntax much simpler.


Yeah since this complicates your parameter sets by adding Path vs
LiteralPath.

--
Keith


My System SpecsSystem Spec
Old 09-11-2006   #4 (permalink)
Lee Holmes [MSFT]
Guest


 

Re: ParameterSetName - How to handle multiple mutual exclusions

LiteralPath actually started out as a SwitchParameter, but that introduces
some much larger issues.

1) Binding from the pipeine (about 80% of the issue.)

Conceptually, Get-Item <filename> | Get-Item should return the same results
as simply Get-Item <filename>

In RC1 builds, the Path property of the incoming object gets bound to the
Path parameter of the cmdlet. Since the Path property of the item can
include wildcard characters, this means that the second Get-Item command
will still do wildcard expansion.

In RC2, the incoming PSPath parameter is instead bound to the LiteralPath
parameter, which does no wildcard expansion.


2) Multiple literal parameters (about 20% of the issue.)

While "Get-ChildItem <Path> -Literal" may make sense, you get into a serious
naming issue if a cmdlet supports mulitple wildcard parameters. For
example:

Select-String -Path <path> -TreatPathAsLiteral -Match
<pattern> -TreatMatchAsLiteral


Granted, the parameter set explosion is something that is uncomfortable
right now, but can be solved in a future release.

--
Lee Holmes [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

"Keith Hill [MVP]" <r_keith_hill@mailhot.moc.nospam> wrote in message
news:%23gJg3rT1GHA.3908@TK2MSFTNGP05.phx.gbl...
>
> "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
> news:eTJc%23PT1GHA.1288@TK2MSFTNGP03.phx.gbl...
>> There's no direct native mechanism for handling complex usages like that.
>> This was one limitation the developers mentioned in private beta days.
>> Trying to represent it in Get-Command would get pretty complex as well,
>> since there are 4 distinct usage statements from that set.
>>
>> The approach I've used is to refactor parameter sets like this.
>>
>> Assuming this is your touch cmdlet, here's how I would probably approach
>> it. I would change this back to a single parameter Time, but make it an
>> object. If it is a filesystem object or a path to an object, you get the
>> time from the object's timestamp. If not, it's parsed as a time.

>
> I'll look into what I can do there. Basically I could accept an Object
> and then hurl if it is not either a string that is a valid path to a file,
> a FileInfo object or a DateTime object.
>
>> Frankly, I would also like to see them change the string[] LiteralPath to
>> just Switch Literal to modify the treatment of the Path parameter. That
>> makes syntax much simpler.

>
> Yeah since this complicates your parameter sets by adding Path vs
> LiteralPath.
>
> --
> Keith
>



My System SpecsSystem Spec
Closed Thread
Update your Vista Drivers Update Your Drivers Now!!

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy to get handle from listbox. How to get listbox from handle? IMAFriend .NET General 0 03-27-2008 08:31 PM
Re: Change your handle Ian Betts Vista General 0 08-04-2007 03:07 PM
Multiple Identies how handle? LenM Vista mail 4 02-23-2007 05:49 PM
ParameterSetName in cmdlets Peter Lee PowerShell 0 11-10-2006 05:22 PM
Control.Handle - How do I get a handle to a control with WinFX iNSaNey Avalon 2 05-14-2006 06:51 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51