Re: Can't pass "[System.IO.FileMode]::Open" as a Constructor argument of "FileStream"

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



> wouldn't you need to use quotes if your path contained spaces?

Yes, you need to use quotes if the argument is going to contain any
characters that are significant to the interpreter.

> doesn't this make it very hard to resolve to the correct member overload?

It certainly does. We use a very complex set of heuristics to determine what
constructor to run.

> Eww. I think I will stick with expression mode (parens) and be a bit
> more explicit. :-)

Agreed - expression mode let's you be very explicit. This is an excellent
point. In fact we'll probably add this as a script writer best practice in
the guidelines we're working on. Thanks.

-bruce

--
Bruce Payette [MSFT]
Microsoft Command Shell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.



"Keith Hill" <r_keith_hill@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:eFdCXp7%23FHA.984@xxxxxxxxxxxxxxxxxxxxxxx
> "Bruce Payette [MSFT]" <brucepay@xxxxxxxxxxxxx> wrote in message
> news:u%23Zq5q4%23FHA.1408@xxxxxxxxxxxxxxxxxxxxxxx
>> What's happening here is that new-object gets 2 arguments - a string
>> naming the type to be constucted and a list of strings to used as
>> arguments to the object constructor. The cmdlet parameter binder looks at
>> these argument strings and converts them into the necessary target
>> objects. Because we're parsing in argument mode, the quotes aren't
>> required and unquoted tokens are treated as strings.
>
> Thanks! This is really good stuff to know. A couple of points. First,
> wouldn't you need to use quotes if your path contained spaces? Second,
> doesn't this make it very hard to resolve to the correct member overload?
> I mean, you have a bunch of strings and then you have to figure out which
> one of potentially many overloads can be type coerced to from string args.
> And even then you could have several overloads that match by coercing the
> string args to various other types. Doesn't that leave you with some form
> of heuristic to pick the best match? Eww. I think I will stick with
> expression mode (parens) and be a bit more explicit. :-)
>
> --
> Keith
>
>


.



Relevant Pages

  • Re: Cant pass "[System.IO.FileMode]::Open" as a Constructor argument of "FileStream"
    ... neither the parens nor the quotes are required so the ... strings and converts them into the necessary target objects. ... In expression mode, ...
    (microsoft.public.windows.server.scripting)
  • Re: VBA output to text editor
    ... You specify your position in the ... <filenumber> is the number of the open file. ... If you had 3 strings that made up an ... back correctly because the strings will have double quotes around it. ...
    (microsoft.public.excel.programming)
  • [opensuse] Re: apache mod_rewrite
    ... outside of quotes and inside double-quote strings but not inside ... single-quote strings. ... based on the intention of it being included in that command, ... If you want to insist that my read of this is incorrect, ...
    (SuSE)
  • Re: RegEx wie =?UTF-8?B?ZsO8cg==?= Standardargumente
    ... wie dies schon bei den Standardargumenten automatisch ... dass die Teile eines Strings die in Quotes stehen ... als ein Teilstring gelten sollen, der Rest an Whitespace zerlegt wird. ...
    (de.comp.lang.java)
  • Re: Unicode Support
    ... oriental user inputs something directly in Unicode. ... in the RosASm MainWindow Messages ... RosAsm always parses the Strings ... from Quotes to Quotes, ...
    (alt.lang.asm)