Skip to content

Bug: Empty Array is projected as null instead of an array of length 0 #2088

@kmahone

Description

@kmahone

Description

Consider the idl:

String[] GetItems();

If the implementation of this function returns an empty array, the CsWinRT projection will return null. But it is expected to return a non-null empty array.

The downside of empty arrays being projected as null is that it forces the consumer to write unnatural code:

string[] items = thing.GetItems();
if (items != null)
{
    foreach (var item in items)
    {
        Console.WriteLine(item);
    }
}

instead of the more idiomatic:

foreach (var item in thing.GetItems())
{
    Console.WriteLine(item);
}

@oldnewthing as FYI.

Steps To Reproduce

See description.

Expected Behavior

See description.

Version Info

2.2.0

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions