static T GetPropertyValue( System.Text.Json.Nodes.JsonObject jso, string membername, T& defaultvalue )

robot_2Generated
code_blocksInput

Description

The GetPropertyValue<T> method is a static extension method provided by the SandboxSystemExtensions class. It is used to retrieve a property value from a JsonObject based on a specified member name. If the property is not found or cannot be converted to the specified type, a default value is returned.

Usage

To use the GetPropertyValue<T> method, you need to pass a JsonObject instance, the name of the member you want to retrieve, and a reference to a default value of type T. The method will attempt to find the member in the JSON object and return its value cast to type T. If the member is not found or cannot be cast, the default value is returned.

Example

// Example usage of GetPropertyValue<T>
using System.Text.Json.Nodes;

JsonObject jsonObject = new JsonObject
{
    ["name"] = "Sandbox",
    ["version"] = 1.0
};

string defaultName = "Unknown";
string name = SandboxSystemExtensions.GetPropertyValue(jsonObject, "name", ref defaultName);

// name will be "Sandbox"

int defaultVersion = 0;
double version = SandboxSystemExtensions.GetPropertyValue(jsonObject, "version", ref defaultVersion);

// version will be 1.0