Skip to content

How to create an option of type string, but available values must be is in a runtime given collection #553

Closed Answered by reduckted
lsoft asked this question in Q&A
Discussion options

You must be logged in to vote

Because the options are shown in a PropertyGrid*, which uses type descriptors and converters to get the properties to display, this can be achieved using a TypeConverter. I've created #554 to demonstrate this. The full code is in that PR, but I'll post the relevant parts here.

First, you need to change the type of the property to some type that wraps the string. In my example I called it RuntimeEnumProxy. It simply stores the string value.

public class RuntimeEnumProxy {
    public RuntimeEnumProxy(string value) {
        Value = value;
    }

    public string Value { get; }

    public override string ToString() {
        return Value;
    }
}

In the options type, add a TypeConverterAtt…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@lsoft
Comment options

@mrlacey
Comment options

@lsoft
Comment options

Comment options

You must be logged in to vote
2 replies
@mrlacey
Comment options

@lsoft
Comment options

Answer selected by lsoft
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants