microsoft / microsoft/Power-Fx
Usage Question: Combining record(values) from several sources in c#
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.4k
- Forks
- 358
- Avg merge
- 10h 34m
- Merged PRs (30d)
- 3
Description
Hi!
Im working on a small c# project of mine in which I want to make it possible for the user to provide custom Json input to a formula, but I also want the engine evaluation to take as input some data from internal sources (dotnet classes).
I would gladly also take some feedback as to the general usage..
Consider this small example (from a test):
file class MyPoco
{
public List<MyPocoLine> Values { get; set; } = new List<MyPocoLine>();
public decimal MyFactor { get; set; }
}
file class MyPocoLine
{
public MyPocoLine(int value) => Value = value;
public int Value { get; }
}
var pocoInstance = new MyPoco() { Values = { new(1), new(2), new(3), new(4) }, MyFactor = 2 };
string expression = $"Sum(Values;Value) * MyFactor";
var engine = new RecalcEngine(new PowerFxConfig(Features.PowerFxV1));
var marshallerProvider = new ObjectMarshallerProvider();
marshallerProvider.TryGetMarshaller(typeof(MyPoco), new(), out var marshaller);
var formulaValue = (ObjectRecordValue)marshaller.Marshal(pocoInstance);
var result = engine.Eval(expression, formulaValue); // How could I additionally provide Json here?
result.TryGetPrimitiveValue(out var primitiveResult); // primitiveResult is 20
var expected = pocoInstance.Values.Sum(f => f.Value) * pocoInstance.MyFactor; // expected is 20
I have gotten both dto / json context to work separately, but I don't quite understand how to combine this.
Any help is apreciated, thanks!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the C# example in the issue, especially RecalcEngine.Eval, ObjectMarshallerProvider, and ObjectRecordValue. Determine how JSON input and the marshalled DTO are intended to be combined, then document the supported usage and verify it with a focused example or test based on the existing scenario.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, developer-experience
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100