Search⌘ K
AI Features

Solution: Drone Telemetry Processor

Explore how to use dynamic binding in C# with the ExpandoObject class and JsonNode to parse JSON data, assign properties dynamically, and add methods at runtime. This lesson helps you understand how to handle drone telemetry data by creating flexible objects that calculate velocity dynamically.

We'll cover the following...
C# 14.0
using System.Text.Json.Nodes;
using System.Dynamic;
string telemetryJson = """{ "altitude": 150, "windResistance": 12.5, "motorSpeed": 4500 }""";
dynamic node = JsonNode.Parse(telemetryJson)!;
dynamic droneState = new ExpandoObject();
droneState.WindResistance = (double)node["windResistance"];
droneState.MotorSpeed = (double)node["motorSpeed"];
droneState.CalculateVelocity = new Func<double>(() =>
{
return (droneState.MotorSpeed / 100.0) - droneState.WindResistance;
});
double velocity = droneState.CalculateVelocity();
Console.WriteLine($"Estimated Horizontal Velocity: {velocity} m/s");
...