vendredi 25 mai 2018

C# read a class tree path in a string and access a value given an instance of that class

In C#, is it possible to read a class tree path in a string and access programmatically a value, given an instance of that class ?

For example:

public class LogGeometricModel
{
  public double SmallEndDiameter { get; set; }
  public double LargeEndDiameter { get; set; }

public class Log
{
  public Guid Id { get; set; }
  public LogGeometricModel GeometricModel { get; set; }
}

public class Solution
{
  public DateTime TimeStamp { get; set; }
  public double Price { get; set; }
  public Log RotatedLog { get; set; }
}

The strings could be something like this (a path in the class tree):

SmallEndDiameter = "Solution/RotatedLog/GeometricModel/SmallEndDiameter"

LargeEndDiameter = "Solution/RotatedLog/GeometricModel/LargeEndDiameter"

Price = "Solution/Price"

Id = "Solution/Log/Id"

By reading those strings, I would like to access the actual values of SmallEndDiameter, LargeEndDiameter, Price and Id.





Aucun commentaire:

Enregistrer un commentaire