MerlinVR / UdonSharp

An experimental compiler for compiling C# to Udon assembly
MIT License
678 stars 89 forks source link

Support DeclarationExpression for method calls with out parameters #43

Open ArcanoxDragon opened 4 years ago

ArcanoxDragon commented 4 years ago

Feature Description: If it's possible to implement, it would be nice for UdonSharp to support C#'s DeclarationExpression for methods with out parameters, such as int.TryParse. This would allow the following code:

int someValue;

if (int.TryParse(inputField.text, out someValue))
{
    // do something with someValue
}

to be condensed into:

if (int.TryParse(inputField.text, out var someValue))
{
    // do something with someValue
}

Should probably also support the discard syntax:

var isNumberValid = int.TryParse(inputField.text, out _);

I know it's only a minor improvement to convenience, but it'd be nice to have if it's an easy addition.

MerlinVR commented 4 years ago

This is planned, but potentially requires some changes to how the scope of variables is handled.

ArcanoxDragon commented 4 years ago

Technically in standard C# the someValue variable on both of the two code blocks in my first post would have the same scoping; it's functionally the same, but cleaner to look at. And the discard syntax simply allows you to ignore the out parameter; it doesn't define a variable at all.