PoshCode Archive  Artifact [11428e74a7]

Artifact 11428e74a7b8c123d814b4b9613a504b6b23ce909c0b62fea27aa0e26f6e7c30:

  • File POC-psnull.ps1 — part of check-in [b5ffef2a01] at 2018-06-10 14:26:06 on branch trunk — powershell converts all string types to strings, including nulls which end up as empty strings. use this if you need to pass a true null as a string to a dotnet api (user: unknown size: 942)

# encoding: ascii
# api: powershell
# title: POC $psnull
# description: powershell converts all string types to strings, including nulls which end up as empty strings. use this if you need to pass a true null as a string to a dotnet api
# version: 0.1
# type: class
# license: CC0
# x-poshcode-id: 893
# x-archived: 2009-02-25T08:03:58
#
#
$a = @"

using System;
namespace ClassLibrary1
{
#proof of concept
public static class Class1
{
public static string Foo(string value)
{
if (value == null)
    return "Special processing of null.";
else
    return "'" + value + "' has been processed.";
}
}
}
"@

$b = @"
using System;
namespace testnullD
{
public class nulltest
{
public nulltest(){}
public override string ToString() {return null;}
}
}
"@
add-type $a
add-type $b
$psnull = new-object testnullD.nulltest
add-type $a
[ClassLibrary1.Class1]::Foo($null)
[ClassLibrary1.Class1]::Foo($psnull)