I'm looking for a library that would allow you to perform reflection on an object using a string, e.g.
class SampleClass {
public SampleClass Child {get; set;}
public string SomeValue {get;set;}
}
var a = new SampleClass { Child = new SampleClass { SomeValue = "v"}};
var parser = new ReflectionParser();
var result = parser.Parse("Child.SomeValue", a);
// result is "v"
If not, I'm considering writing one and open sourcing it - but I didn't want to re-invent the wheel. Initially it would just get property values, but in the longer term I could see it gaining the ability to running methods, parsing arguments as need be.
The closest I have found is an XPath style library http://ift.tt/2mnMZVD referenced in Using an XPath-style Query with Reflection and Traversing an arbitrary C# object graph using XPath/applying XSL transforms - however this doesn't appear to be available any more.
Aucun commentaire:
Enregistrer un commentaire