Hi @SCG , Welcome to Microsoft Q&A,
In C#, if you need to access non-public members of an object, you usually use reflection. Through reflection, you can access private fields, properties, or methods of a class.
using System;
using System.Reflection;
class Program
{
static void Main()
{
var customer = new Customer();// Assume you have a Customer object
Type customerType = customer.GetType();
// Get the value of the m_customerModel field
var mCustomerModelField = customerType.GetField("m_customerModel", BindingFlags.NonPublic | BindingFlags.Instance);
var mCustomerModelValue = mCustomerModelField.GetValue(customer);
// Get the value of the UserDefinedFlds field
var userDefinedFldsField = mCustomerModelValue.GetType().GetField("UserDefinedFlds", BindingFlags.NonPublic | BindingFlags.Instance);
var userDefinedFldsValue = userDefinedFldsField.GetValue(mCustomerModelValue);
// Get the value of the UsrDfnd1 field
var usrDfnd1Field = userDefinedFldsValue.GetType().GetField("UsrDfnd1", BindingFlags.NonPublic | BindingFlags.Instance);
var usrDfnd1Value = usrDfnd1Field.GetValue(userDefinedFldsValue);
Console.WriteLine(usrDfnd1Value); // Output: Hello There
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.