Skip to content

Add an "auto" property class #3

@bladeoflight16

Description

@bladeoflight16

C# has some nice syntax that allows you to avoid explicitly creating an extra, underlying instance variable to store the value when your variable doesn't have any extra processing:

public String MyString { get; set; }

I believe it would be possible to provide an out of the box implementation of this by extending your Property class. I imagine it would look something like this:

public class AutoProperty<T> extends Property<T> {
    private T value;
    public AutoProperty() {
        super(() -> this.value, newValue -> this.value = newValue);
    }
}

Then it would be used like this:

public class MyClass {
     public Property<String> myString = AutoProperty<String>();
}

(I haven't fully flushed out the implications of this code. It's just an example implementation to start off with.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions