0

I am not sure if this is possible or not.

Lets say a I have class C1 that have a List<double> inside:

class C1{
    List<double> theList {get;set}
    double someVar {get;}
}

I can get somevar through the string path "C1.somevar" and the same thing is valid for the list. However, is there a way for me to use string paths to retrieve a specific element of the list? Something like "C1.theList.0"

The reason behind is that in OxyPlot I want to be able to set the DataFielYof a LineSeries to a specific element in the list.

Cheers

  • 2
    Have you tried `"C1.theList[0]"`? – juharr Sep 20 '17 at 12:10
  • 1
    Show your current code. Or rather, see any of the duplicates. – CodeCaster Sep 20 '17 at 12:10
  • @juharr this question is about reflection, accessing a collection element by index, using a string. – CodeCaster Sep 20 '17 at 12:11
  • @CodeCaster I'm not familiar with oxyplot so I was just throwing out a suggestion. – juharr Sep 20 '17 at 12:12
  • 1
    @juharr I suspect reflection purely based on the phrase "string path", so we're both guessing. ;) – CodeCaster Sep 20 '17 at 12:12
  • if you want to speed up the guessing game, you can add further information to your post to describe a little more in detail what you are trying to do and what exactly you mean with **string path**. do you have an actual example how you "get `somevar` through the string path "C1.somevar"" – Mong Zhu Sep 20 '17 at 12:16
  • @JulianoFranz it's long time since I last used OxyPlot, I don't remember what it is uses (especially in newer versions) to resolve the property value. Possible workarounds: if it supports dynamic types (just try) you can have your own collection with `ExpandoObject` where items (0, 1, ...) are in fact properties. To do it you have to cast the `ExpandoObject` to `IDictionary` and binding path may be `C1.theList.0` as you wish. If OxyPlot does not support this (highly possible) you still can add support for yourself... – Adriano Repetti Sep 20 '17 at 12:39
  • 2) Alternatively, if I remember correctly, there is a `Mapping` property you can use for _custom_ mapping between items in `ItemsSource` and `DataPoint`. – Adriano Repetti Sep 20 '17 at 12:39

0 Answers0