C#, access child properties from parent reference?

后端 未结 5 940
孤城傲影
孤城傲影 2020-12-21 11:31
public void GetProps(Parent p){

   // want to access lots of child properties here
   string childProp1 = p.prop1;
   bool childProp2 = p.prop2;
   bool childProp3          


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-21 12:03

    If the property is defined in an intermediate class between parent and child and you don't have a reference to that intermediate class at design time then you could use reflection to get the property. But it sounds like you should be using the most relevant sub parent instead of simply parent.

提交回复
热议问题