简体   繁体   中英

C# Reflection, how to get the value of a composite object

I have a patient object which has a statement object. I want to get the values of all patient object and statement object using reflection.

public class Patient
{    
    public string Name { get; set; }    
    public string Address { get; set; }    
    public Statement Statement { get; set; } 
}

To get the Statement property value of an object using reflection:

System.Reflection.PropertyInfo property = 
    object.GetType().GetProperty("Statement", BindingFlags.Instance);

object statement = property.GetValue(object);

But since you already know all the details of Patient and Statement what's the point using reflection?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM