Replies: 3 comments 12 replies
-
You've actually nailed the problem! All of the interfaces in .NET MAUI are read-only; the interface properties only have getters, no setters. So the only way to set a property based on the usage of a |
Beta Was this translation helpful? Give feedback.
-
@mrlacey, actually using SGs (Incremental Source Generators, in this case) can be less code to maintain and more flexibility. So for reference, I'll take your PR #141, here all the methods just grab a value, set it to the property, and return the public static TVisualElement Width<TVisualElement>(this TVisualElement element, double widthRequest) where TVisualElement : VisualElement
{
element.WidthRequest = widthRequest;
return element;
} So in this case we do it for all properties inside From a general point of view, you can say that SG is a
So at the end of the day, we will have one code that will generate those methods and if in the future .NET MAUI add more properties, the SG will see that and generate the methods, so we don't need to open a PR adding more extensions methods. Of course, there are cases where writing down the methods is a best solution, for cases like this having a SG, IMHO is better.
This isn't true, because we use
Why do you've this feeling? TBH, writing a SG for this isn't that hard. If you never wrote one I'll be more than happy to guide you through the process (if we choose to re-implement your PR using SG) |
Beta Was this translation helpful? Give feedback.
-
Closed as per the Community Stand-up discussion here: https://youtu.be/N9wMcBP4jtg?t=2889 |
Beta Was this translation helpful? Give feedback.
-
Following on from #142 (comment)
What's the benefit of using Source Generators here?
Doesn't it make testing and documenting of the available functionality harder?
In that the amount of effort to write the code for the generator is approximately equivalent to writing the methods that would be generated directly, the fact that what will be generated will (almost?) always be the same it looks like work is being unnecessarily duplicated and offloaded to the consumer of the library when it could be done once.
It's the difference between writing and compiling the code once when the library is created, or generating and compiling that code every time every consuming app is built. That feels like a waste of compilation effort by duplicating the task (even though, admittedly very small) for every app that's built rather than just doing it once when the library is created.
The only benefit I see with the way that the current Source Generator implementation works with
ITextAlignment
means that it it will automatically add support for any new controls in the Microsoft.Maui.Controls assembly that also implement this interface.However I'd expect (although I haven't yet checked) it would be possible to achieve the same things by building an extension based on the interface.
It feels like the use of Source Generators is unnecessary and doesn't really add any real benefit. It just makes the codebase more complicated as there are some features and required markup functionality that can't be created this way.
Beta Was this translation helpful? Give feedback.
All reactions