Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Support DeclarationExpression for method calls with out parameters #43

Open
ArcanoxDragon opened this issue Jun 21, 2020 · 2 comments
Open
Labels
enhancement New feature or request
Milestone

Comments

@ArcanoxDragon
Copy link

ArcanoxDragon commented Jun 21, 2020

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.

@ArcanoxDragon ArcanoxDragon added the enhancement New feature or request label Jun 21, 2020
@MerlinVR
Copy link
Owner

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

@ArcanoxDragon
Copy link
Author

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.

@MerlinVR MerlinVR added this to the UdonSharp 1.0 milestone Sep 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants