mvvmgen
mvvmgen copied to clipboard
Custom getter for properties for lazy loading
Currently with PropertyCallMethodAttribute we can add method calls for property setters but getters will always only use the backing field.
Please add an other attribute for getter to support lazy loading. Example:
class A
{
[Property]
[CustomGetter(LazyLoadTest)]
private List<string> _test;
private List<string> LazyLoadTest(List<string> currentValue)
{
return currentValue ?? new List<string>(){"testA", "testB"};
}
#region Generated
public List<string> Test
{
get => _test = LazyLoadTest();
set =>
{
// No changes
}
}
#endregion
}
This getter implementation is just a sample, I'm not sure this is best one.
Thank you @ADIX7 for this issue. I'll think about custom getters and what makes sense there.
+1 on this
Having a ready-to-use async lazy load implementation would be awesome.
Hey everyone, this one is open since a while.
What's the reason why this could be a great addition? I mean, the properties are read anyway via data binding, so lazy loading wouldn't save much, as everything is loaded from the beginning. Am I missing something? What are the scenarios where you would need this and where it would really improve memory or other things?
Thankful for anything that helps me to understand this a bit more.
It was quit a long time ago, so I'm not sure what was the specific reason I needed this. I think of 2 things:
- A property that needs high computational but not used on every view (probably this was my case)
- Some dependency is not in a given state when the constructor runs but will be when the property is first accessed
Also, beside the lazy feature with this we can add logic to the getter (e.g. validation). Although I'm not if this would be the best place for that, but there might be other scenarios where this can be helpful.
Thank you @ADIX7 , I'll think more about this and consider it for the next release.