-
Notifications
You must be signed in to change notification settings - Fork 700
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
Width and Height are throwing before IsInitialized is true. #3324
Comments
This is the correct behavior. Do not set Width or Height of autosize is true. It makes no sense to do so. |
Please, can you understand this. On the constructor we are setting the properties, no matter what order is used. So, we are collecting data for further process. After initialized, if WindowsTerminal_XOjkXRKVD2.mp4 |
Setting properties in an initializer is not a constructor. All it does is set the properties specified in the order provided. To fix your code simply set AutoSize = false in the initializer before you set Width or Height. |
I know that, but it's on an object initializer. Did you forget that now mostly of the views are parameter less constructors.
That is the correct way if the properties are passed on the constructor parameter, but not now.
Where is that documented? Why a hell a user will bother with that on an object initializer? You was right when you said since a long time ago that the properties checking should be done after a view is initialized, but now you are being incoherent with yourself. See the changed unit test f2998e0. Maybe now you understand this better now. Note: |
These three blocks of code do exactly the same thing: Label label = new ()
{
Width = 1,
AutoSize = false
}; Label label = new ();
label.Width = 1;
label.AutoSize = false; View view = new ();
view.AutoSize = true;
view.Width = 1;
view.AutoSize = false; All three of these examples are INCORRECT and will cause the exception to be thrown telling the programmer they've made a mistake. In these 2 PRs, the behavior of AutoSize was updated to be more deterministic. Specifically, I made it clear that if
When I coded this, I explicitly added the exception on the setters to help find any code that was setting I failed to update the API docs to reflect this. The API docs for
|
But why you don't understand that the user want to set |
But why don't you understand that in a C# intializer, the order in which you set properties matters. If the user wants to set Label label = new ()
{
AutoSize = false
Width = 1,
}; |
Because in my opinion that isn't mandatory. As you can see in my test if the user set badly after initialization the |
I understand perfectly. This has NOTHING to do with The rule of "Don't set Height or Width if AutoSize is true" applies ALWAYS. I mean, it COULD be softened to only apply if |
Ah ok that is an explanation that I understand because will be big changes. |
There's a really important distinction between an initializer and explicit sequential assignments that makes this statement not true. An initializer is special in that the object reference is not pushed onto the evaluation stack if the initializer does not complete successfully. You can sorta consider it as an appendix to whichever constructor was used. If an exception happens in the first example, you never have a Label object, the newobj never returned a reference, and the heap allocation that was performed is already GC-eligible. In the second and third examples, the Label and View objects do exist and their references are currently on the stack, and their heap allocations have valid live handles in the current scope. Concepts such as init accessors and the Key points:
|
And thinking about it anyway... Throwing an exception in the setters for that is bad form. One reason is precisely the fact that the order of setting the properties matters in a program-breaking way. Property setters are supposed to avoid exceptions unless critically necessary and are supposed to try to keep things in a consistent state if they encounter exceptional situations within themselves. Proper behavior would be for the setter to check AutoSize first and immediately return without making any state changes if the operation would be illegal. |
I know throwing exceptions from setters is bad form. I also know initializers are special in how you point out. That's all irrelevant to this topic. I put the exception in to find code that was using AutoSize wrong. It is doing its job. AutoSize is going away Once Dim.Auto is done. |
Closing as by design. |
When setting the Dim
Width
andHeight
before setAutoSize
to false throwsSystem.InvalidOperationException: 'Must set AutoSize to false before setting Width.'
Running this unit test will fail.
The text was updated successfully, but these errors were encountered: