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

custom types for System.Int32

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 09-24-2007   #1 (permalink)
ASCHNEIDER146
Guest


 

custom types for System.Int32

I am trying to add a custom ScriptMethod to System.Int32

I have the following XML file that I load with Update-TypeData

<Types>
<Type>
<Name>System.Int32</Name>
<Members>
<ScriptMethod>
<Name>Test</Name>
<Script>
write-host $this
</Script>
</ScriptMethod>
</Members>
</Type>
</Types>

If I run the command
$int = 5
$int.test()

I get my result as expected. It writes itself ($this) to the console.\

However, if I try to run the method directly on the number 6 I get a
bad constant error

PS 8 > 6.test()
Bad numeric constant: 6.times.
At line:1 char:7
+ 6.times <<<< ()

If I pipe 6 to get-member i see my custom member is there

Any ideas ?

Thanks,

Andy


My System SpecsSystem Spec
Old 09-24-2007   #2 (permalink)
Keith Hill [MVP]
Guest


 

Re: custom types for System.Int32

"ASCHNEIDER146" <aschneider146@xxxxxx> wrote in message
news:1190664707.833567.174800@xxxxxx
Quote:

> I get my result as expected. It writes itself ($this) to the console.\
>
> However, if I try to run the method directly on the number 6 I get a
> bad constant error
>
> PS 8 > 6.test()
> Bad numeric constant: 6.times.
> At line:1 char:7
> + 6.times <<<< ()
>
> If I pipe 6 to get-member i see my custom member is there
>
> Any ideas ?
You get this behavior even if you were to try ToString:

266# 6.tostring()
Bad numeric constant: 6.tostring.
At line:1 char:10
+ 6.tostring <<<< ()

Try it this way:

267# (6).tostring()
6

--
Keith




My System SpecsSystem Spec
Old 09-24-2007   #3 (permalink)
ASCHNEIDER146
Guest


 

Re: custom types for System.Int32

On Sep 24, 1:56 pm, "Keith Hill [MVP]"
<r_keith_h...@xxxxxx_no_spam_I> wrote:
Quote:

> "ASCHNEIDER146" <aschneider...@xxxxxx> wrote in message
>
> news:1190664707.833567.174800@xxxxxx
>
Quote:

> > I get my result as expected. It writes itself ($this) to the console.\
>
Quote:

> > However, if I try to run the method directly on the number 6 I get a
> > bad constant error
>
Quote:

> > PS 8 > 6.test()
> > Bad numeric constant: 6.times.
> > At line:1 char:7
> > + 6.times <<<< ()
>
Quote:

> > If I pipe 6 to get-member i see my custom member is there
>
Quote:

> > Any ideas ?
>
> You get this behavior even if you were to try ToString:
>
> 266# 6.tostring()
> Bad numeric constant: 6.tostring.
> At line:1 char:10
> + 6.tostring <<<< ()
>
> Try it this way:
>
> 267# (6).tostring()
> 6
>
> --
> Keith
Cool, That seemed to work. Thanks

Andy

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
types.custom.ps1xml for custom members hasten PowerShell 0 02-25-2008 08:30 PM
Error: "Cannot convert "System.Object[]" to "System.Int32"." Shay Levi PowerShell 3 01-31-2008 04:16 AM
Unable to associate file types to custom application Steinar Haugen Vista file management 2 04-18-2007 05:25 AM
Using add-member with System.Int32 Marco Shaw PowerShell 2 03-02-2007 04:29 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