In my blazor webassembly app I would like to evaluate string paths like:
"Property1.Property2"- optionally
Property1[index]andProperty1["key"] - optionally
Method1().Property2
The requirements are:
- I'm able to compile/cache the expression somehow and evaluate it multiple times with different parameter (parameter = source object). Speed is important
- I need to evaluate the path in order to get value
- I need to be able to set value if the path points to a property.
- I need to be able to get the MemberInfo, although this could be done externally using different evaluator.
I do not need to evaluate mathematical expression like Property1 * Property2
What do I have
I have used RoslynAPI, simmilar to this:
var discountFilter = "album => album.Quantity > 0";
var options = ScriptOptions.Default.AddReferences(typeof(Album).Assembly);
Func<Album, bool> discountFilterExpression = await CSharpScript.EvaluateAsync<Func<Album, bool>>(discountFilter, options);
var discountedAlbums = albums.Where(discountFilterExpression)
but I cannot use Roslyn in my Blazor WebAssembly apps, because it it too heavy.
Is there a more lightweight way of evaluating paths, that preferably builds expressions?