0

I have a static class StaticDataValues. In this class I instantiate my value classes:

public static class StaticDataValues
{
    public static Floor Floor = new Floor ();
    public static Kitchen Kitchen = new Kitchen ();
}

In other classes (e.g. in a WPF UserControl) I want to use (e.g.) Kitchen.

private void InitializeEventNotifications()
{
    StaticDataValues.Kitchen.Raffstore.ElementAt(this.ID).Status.ValueChanged += (s, e) =>
    {
        var value = s as Home.Automation.Beckhoff.VarModel.VarItemBool;

        if (value != null)
        {
            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                new Action(() => this.ButtonAuto.Button.IsCheckedvalue.Value));
        }
    };
}

How can I change this Kitchen to Floor dynamically (over a property)? Is this possible?

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
  • Does this answer your question? [Get property value from string using reflection](https://stackoverflow.com/questions/1196991/get-property-value-from-string-using-reflection) – Peter Duniho Apr 10 '21 at 19:07
  • See also https://stackoverflow.com/questions/7649324/c-sharp-reflection-get-field-values-from-a-simple-class. Note that your question is not _about_ static classes, so those tags are inappropriate, as is the [tag:wpf] tag. I've added the relevant tags for you. Finally, note that the word "generic" has a very specific meaning in the context of C#. I'm not sure either "generic" or "general" really belongs in your title, but I replaced the wrong word with what you probably meant to ensure against any confusion, since this question has nothing to do with C# generics. – Peter Duniho Apr 10 '21 at 19:08
  • Noe that every access to e.g. your `StaticDataValues.Floor` property creates and returns a new instance. Is this really what you want? – Klaus Gütter Apr 11 '21 at 01:58

0 Answers0