-
So I just got namespace MyApp
{
public class TestWindow : Adw.ApplicationWindow
{
[Gtk.Connect] private readonly Gtk.Button _runButton;
public TestWindow(Adw.Application app, Gtk.Builder builder) : base(builder.GetPointer("_root"), false)
{
Application = app;
builder.Connect(this);
_runButton.OnClicked += (sender, args) =>
{
Console.WriteLine("Hey!");
};
}
public TestWindow(Adw.Application app) : this(app, new Gtk.Builder("window.ui"))
{
}
}
} Using The code itself works fine, but the fact that the warning is there makes me feel like something is wrong and there must be a way to do it warning-free. Any advice? Is the only option to suppress compiler warnings? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Okay so I've searched through GitHub to see what others did, and they either do nothing or use I think I'll just use |
Beta Was this translation helpful? Give feedback.
It is currently a bit odd, I agree. As the fields are filled via reflection the flow analysis can't know about the initialization if you are using some
*.ui
files.You could either not use
*.ui
files or initialize your member via[Gtk.Connect] private readonly Button button = default!;
to have a none nullable field which gets initialized to value which is null, but not null for the compiler. As it is filed via reflection afterwards it should be fine as long as your*.ui
file does not break.The long term goal is to remove all the reflection code from the project which requires explicit initialization of the fields. This will probably happen via source generators to make life easier for th…