-
Notifications
You must be signed in to change notification settings - Fork 685
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
View
initialization override lacks tests and ISupportInitialize.BeginInit
/EndInit
should be virtual
#2235
Comments
So We could skip /// <summary>
/// This derived from <see cref="ISupportInitializeNotification"/> to allow notify all the views that are beginning initialized.
/// </summary>
public void BeginInit ()
{
if (!IsInitialized) {
oldCanFocus = CanFocus;
oldTabIndex = tabIndex;
}
if (subviews?.Count > 0) {
foreach (var view in subviews) {
if (!view.IsInitialized) {
view.BeginInit ();
}
}
}
+ BeginInitImpl ();
}
+protected virtual void BeginInitImpl()
+{
+
+}
/// <summary>
/// This derived from <see cref="ISupportInitializeNotification"/> to allow notify all the views that are ending initialized.
/// </summary>
public void EndInit ()
{
IsInitialized = true;
if (subviews?.Count > 0) {
foreach (var view in subviews) {
if (!view.IsInitialized) {
view.EndInit ();
}
}
}
- Initialized?.Invoke (this, EventArgs.Empty);
+ OnInitialized ();
}
+protected virtual void OnInitialized()
+{
+ Initialized?.Invoke (this, EventArgs.Empty);
+}
|
@kzu I agree allowing override these functions to perform additional initialization and invoke the event as desired. Is advised preserve some initial settings like, |
Ok, so I see two slightly different opinions on this :). To sumarize, I think they would be:
public virtual void BeginInit() => ...
public virtual void EndInit() => ... Benefits: clearly and intuitively convey these are supported extensibility hooks. It's the way a lot of .NET and UI frameworks work.
public void BeginInit()
{
OnInitializing();
...
}
public void EndInit()
{
....
OnInitialized();
}
protected virtual void OnInitializing() { }
protected virtual void OnInitialized() { } I think I'm fine with both. In the second case, I think it's slightly annoying that BeginInit/EndInit are part of the public API, yet not intended to be invoked by anyone other than the Option 1 seems like it would be most natural given that both BeginInit and EndInit are already public. 🤔 |
Should public void BeginInit()
{
...
OnInitializing();
} The union of both options has no sense or have? |
I think the union of both could work too, yeah. Given the current implementation, perhaps public virtual void BeginInit ()
{
if (!IsInitialized) {
oldCanFocus = CanFocus;
oldTabIndex = tabIndex;
}
OnInitializing();
if (subviews?.Count > 0) {
foreach (var view in subviews) {
if (!view.IsInitialized) {
view.BeginInit ();
}
}
}
} |
Let's see the @tznind opinion. |
These all sound like good solutions. I think I've been converted from my initial response and I'm now feeling that simplicity might be the best and simply marking them virtual as @kzu first suggested. If someone forgets to call The |
Yeah, that was my initial gut feeling too. Devs extending types via inheritance should know already how to properly handle overriding virtual members and invoking base as appropriate. Eventually the library could be made smarter and warn/fix this for users if they forget 😉 |
Wow @kzu great API packages you have done and doing, fantastic. Don't give up creating useful libraries, please. Thanks. |
Related... I added I also noted that no existing code in the solution cares one way or another. I also noted there's no code that exercises I've updated the title of this Issue as a result. |
View
initialization override lacks tests and ISupportInitialize.BeginInit
/EndInit
should be virtual
Since View is intended to be heavily inherited to create new types of views, it would be quite convenient to be able to override
BeginInit
andEndInit
, so that additional automatic initialization can be performed.This is the typical pattern for interfaces that can be of use to derived classes (i.e. IDisposable and the virtual Dispose impl.).
If desired, the interface implementation can be made explicit and a protected virtual member can be exposed instead, to preserve the base class behavior even if overriden. The former is simpler, but the latter might be more solid if the base View performs critical work on its BeginInit/EndInit pair.
(I can send a PR with whichever approach is deemed more appropriate)
The text was updated successfully, but these errors were encountered: