Implementing Dynamic Data Binding from JSON
Posted: 29 Apr 2024, 18:53
Hello,
I am involved in a project where the primary game logic is developed in Rust, and we look into possibly using NoesisGUI as a UI middleware.
Typically, NoesisGUI expects data models to be statically defined in C++ subclasses, with specific properties (like Name and Health for a Player). However, defining every possible data model from our Rust codebase in C++ would dramatically increase the interop complexity and maintenance overhead. We are exploring ways to dynamically generate these data models based on arbitrary JSON inputs from Rust to avoid this overhead.
Consider an example like this:
Input:
Outcome in XAML:
This could illustrate how I would like to dynamically bind incoming JSON data to UI components in NoesisGUI without pre-defining a C++ class for Player. In other words a system where UI components can dynamically adapt to the data structure defined in JSON.
Is something like this possible using dynamic reflection? If so, could you provide any reference or guidance how to start with implementation of such system?
Thank you for your help!
I am involved in a project where the primary game logic is developed in Rust, and we look into possibly using NoesisGUI as a UI middleware.
Typically, NoesisGUI expects data models to be statically defined in C++ subclasses, with specific properties (like Name and Health for a Player). However, defining every possible data model from our Rust codebase in C++ would dramatically increase the interop complexity and maintenance overhead. We are exploring ways to dynamically generate these data models based on arbitrary JSON inputs from Rust to avoid this overhead.
Consider an example like this:
Input:
Code: Select all
"Player": {
"Name": "John Doe",
"Health": 42
}
Code: Select all
<ResourceDictionary>
<Player x:Key="Player" Name="John Doe" Health="42"/>
</ResourceDictionary>
Is something like this possible using dynamic reflection? If so, could you provide any reference or guidance how to start with implementation of such system?
Thank you for your help!