"Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:O%23QcHh%23lHHA.1216@TK2MSFTNGP03.phx.gbl...
> C# novice...
>
> It would appear that "object" is a reserved word in C#. At least I cannot
> seem to easily declare a variable with the name "object".
Yes it is language shorthand for System.Object. Just like string is short
for System.String.
> I'm writing a cmdlet, and I actually want one of the parameters to be
> named "object".
>
> Is there some way I can make it work?
>
> For now, I just do something like this:
>
> private string _myObject;
> [Parameter(Position = 2)]
> [ValidateNotNullOrEmpty]
> public string myObject
> {
> get { return _myObject; }
> set { _myObject = value; }
> }
>
You can use this syntax "@Object" to tell the compiler that Object is the
property name and doesn't refer to System.Object. However I would consider
renaming the paramter. Write-Host is the only cmdlet I see that uses a
param named Object. Others use:
InputObject, DifferenceObject, ReferenceObject, TargetObject, AclObject
694# gcm -type cmdlet | select @{n='CmdletName';e={$_.Name}} -expand
ParameterSets | select CmdletName -expand Parameters | ? {$_.Name -match
'object'} | Sort Name | ft CmdletName, Name -a
--
Keith