The GetValue
method retrieves the value of a specified property or field from a given instance. This method is part of the TypeDescription
class, which provides a safe way to interact with types in the Sandbox environment.
The GetValue
method retrieves the value of a specified property or field from a given instance. This method is part of the TypeDescription
class, which provides a safe way to interact with types in the Sandbox environment.
To use the GetValue
method, you need to provide an instance of the object from which you want to retrieve the value, and the name of the property or field as a string. The method returns the value as an object
.
Ensure that the property or field name provided exists on the instance, otherwise, the method may throw an exception or return null
.
// Example usage of GetValue method TypeDescription typeDescription = new TypeDescription(); object instance = new MyClass(); string propertyName = "MyProperty"; // Retrieve the value of 'MyProperty' from the instance object value = typeDescription.GetValue(instance, propertyName); // Cast the value to the expected type int intValue = (int)value;