XSharpPublic
XSharpPublic copied to clipboard
Cannot use event assignment in object initializer
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
Hmm, looks like it's not supported in c# either, but it's on the todo list:
https://github.com/dotnet/csharplang/discussions/307 https://github.com/dotnet/csharplang/issues/5176
maybe we keep this incident open, for when/if the feature gets implemented in Roslyn