1
Vote

Parameters of type Int show up as <Nullable`1[Int32]> in help

description

Parameters of type Int in PS are showing up as <Nullable`1[Int32]> in the help editor. Any ideas what's needed to be done?

comments

Camelot wrote May 6, 2015 at 7:20 AM

What you get when you run Get-Help cmdlet against your command?

devkays wrote May 6, 2015 at 8:20 AM

It's the same

PS C:\Windows\System32\WindowsPowerShell\v1.0> get-help Add-AzureVMDataDisk

NAME
Add-AzureVMDataDisk
SYNOPSIS
Add Data Disk to VM

SYNTAX
Add-AzureVMDataDisk [-VM] <PSVirtualMachine> [-Name] <String> [[-VhdUri] <String>] [[-Caching] <String>] [-DiskSizeInGB] <Nullable`1[Int32]> [[-Lun] <Nullable`1[Int32]>] [-CreateOption] <String> [[-SourceImageUri] <String>] [-Profile <AzureProfile>] [<CommonParameters>]

DESCRIPTION
This cmdlets allows you to add a Data Disk to the VM at creation time or to an existing VM

I also discovered that this is also happening with other types

PS C:\Windows\System32\WindowsPowerShell\v1.0> Switch-AzureMode AzureResourceManager

PS C:\Windows\System32\WindowsPowerShell\v1.0> get-help Set-AzureVMOperatingSystem -Full
-Secrets <list`1[psvaultsecretgroup]>
    Secrets config that specifies the source KeyVault and Certificate url. Use the Add-AzureVMSecret cmdlet to create this config.

    Required?                    false
    Position?                    5
    Default value                
    Accept pipeline input?       true (ByValue, ByPropertyName)
    Accept wildcard characters?  false

-AdditionalUnattendContents <list`1[psadditionalunattendcontent]>
    AdditionalUnattendContent config. Use the Add-AzureVMAdditionalUnattendContent cmdlet to create this.

    Required?                    false
    Position?                    12
    Default value                
    Accept pipeline input?       true (ByValue, ByPropertyName)
    Accept wildcard characters?  false

Camelot wrote May 6, 2015 at 10:49 AM

Looks like this type is defined in the parameter metadata (where editor extracts paramter types). So I don't see anything wrong here.

devkays wrote May 19, 2015 at 10:52 PM

@Camelot - Can you let me know where the "parameter metadata" resides or is defined? We can take a look at fixing it there

Camelot wrote May 20, 2015 at 10:28 AM

In the cmdlet definition. Where you define parameters and their types.

devkays wrote May 20, 2015 at 6:02 PM

Camelot wrote May 20, 2015 at 8:15 PM

You should remove a question mark from the type:
int? ==> int
Question mark on non-nullable (by default) types means "nullable". Non-nullable default types are also blittable.

devkays wrote May 29, 2015 at 9:09 PM

I discussed a few options on this with the dev team, pasted below
It’s actually simpler in the code to expose “int?”:
•   User specifies any int value => int value 
•   User doesn’t specify anything => null
o   No checking needed, directly pass it to the client library call

If you change it to “int”:
•   User specifies any int value => int value, i.e. “0”
•   User doesn’t specify anything => 0
o   For this you would need more code to check whether user explicitly specifies “0” or not

Furthermore, if a “null” value means “no change” in the client library, changing it to non-nullable “int” would either:
•   Limit the functionality of using “null”, or
•   Need to provide more codes for checking “specified” or “not specified”.
Then we decided if you could make the tool be able to recognize any .NET types (generic or non-generic), instead of we limit the usage of types in the code. Ask below
The ask is to correctly parse .NET nullable or any generic type.

The problem is that in .NET reflection, when you get the generic type string directly, like the following pseudo code:
•   $obj.GetType().Name  

It’s going to be like “Nullable`1[Int32]”, by design.

The correct way is to design the helper design so that it can correctly parse it, like the following pseudo code:
•   if (IsInNullableInt32Type($obj)) return “int?”;