Skip to content
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

Custom getter for properties for lazy loading #23

Open
ADIX7 opened this issue Jan 11, 2022 · 5 comments
Open

Custom getter for properties for lazy loading #23

ADIX7 opened this issue Jan 11, 2022 · 5 comments
Assignees
Labels
feature proposal New feature or request

Comments

@ADIX7
Copy link

ADIX7 commented Jan 11, 2022

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.

@ADIX7 ADIX7 changed the title Custom getter for properties Custom getter for properties for lazy loading Jan 11, 2022
@thomasclaudiushuber
Copy link
Owner

Thank you @ADIX7 for this issue. I'll think about custom getters and what makes sense there.

@thomasclaudiushuber thomasclaudiushuber added the feature proposal New feature or request label Feb 6, 2022
@TopperDEL
Copy link

+1 on this

Having a ready-to-use async lazy load implementation would be awesome.

@thomasclaudiushuber thomasclaudiushuber self-assigned this Mar 30, 2023
@thomasclaudiushuber
Copy link
Owner

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.

@ADIX7
Copy link
Author

ADIX7 commented Dec 11, 2023

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:

  1. A property that needs high computational but not used on every view (probably this was my case)
  2. 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.

@thomasclaudiushuber
Copy link
Owner

Thank you @ADIX7 , I'll think more about this and consider it for the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature proposal New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants