darxis / EntityFramework.LazyLoading

LazyLoading for EF Core
MIT License
21 stars 4 forks source link

Improve LazyReference<T> with [CallerMemberName] #21

Closed gnaeus closed 7 years ago

gnaeus commented 7 years ago

We can simplify API of LazyReference<T> by using [CallerMemberName] attribute:

public sealed class LazyReference<T>
{
    public T GetValue(object parent, [CallerMemberName] string referenceName = null);
}

And we can write

private LazyReference<Parent> _parentLazy = new LazyReference<Parent>();
public Parent Parent
{
    get => _parentLazy.GetValue(this);
    set => _parentLazy.SetValue(value);
}

instead of

get => _parentLazy.GetValue(this, nameof(Parent));
darxis commented 7 years ago

This is awesome, I haven't heard of this attribute before. Feel free to submit a PR, it will not break compatibility :)