Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use event assignment in object initializer #1313

Open
cpyrgas opened this issue Aug 17, 2023 · 1 comment
Open

Cannot use event assignment in object initializer #1313

cpyrgas opened this issue Aug 17, 2023 · 1 comment

Comments

@cpyrgas
Copy link

cpyrgas commented Aug 17, 2023

https://www.xsharp.eu/forum/public-product/3619-event-registration-in-class-initializer#27330

This compiles without errors:

oMenuItem := MenuItem{}{ Name := "Exit", Checked := FALSE}

This one:

oMenuItem := MenuItem{}{ Name := "Exit", Checked := FALSE, Click += test}

FUNCTION Test(o AS OBJECT, e AS EventArgs) AS VOID

reports:

error XS1922: Cannot initialize type 'System.Windows.Forms.MenuItem' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
error XS0747: Invalid initializer member declarator
error XS0103: The name 'Name' does not exist in the current context
error XS0747: Invalid initializer member declarator
error XS0103: The name 'Checked' does not exist in the current context
error XS0747: Invalid initializer member declarator
error XS0103: The name 'Click' does not exist in the current context
@cpyrgas cpyrgas added this to To do in Build 2.18 via automation Aug 17, 2023
@cpyrgas
Copy link
Author

cpyrgas commented Aug 17, 2023

Hmm, looks like it's not supported in c# either, but it's on the todo list:

dotnet/csharplang#307
dotnet/csharplang#5176

maybe we keep this incident open, for when/if the feature gets implemented in Roslyn

@cpyrgas cpyrgas removed this from To do in Build 2.18 Aug 17, 2023
@cpyrgas cpyrgas added enhancement and removed bug labels Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant