开发者

Implementation of Generic Method in Base Class

I have Base Class as Class A, and Class B and Class C is derived from class A. Now I want to implement static method in Base Class A as ConvertObjectIntoXML(Type t) and ConvertXMLIntoObject(string XML). Class A has set of Properties and Class B and Class C add few more properties. Now if user passes object Type B into ConvertObjectIntoXML(typeof class B) and I want to parse through all Properties of Class B and spit out XML.

Now my questions is will I be able to access all properties (using code below) of Class A and additional properties of class B which exist only in B ?

Type t开发者_运维技巧 = aClass.GetType();
PropertyInfo[] pi = t.GetProperties();
foreach(PropertyInfo prop in pi)
   Console.WriteLine("Prop: {0}",  prop.Name);

Thanks Ocean


You already have the code, why not try it? And yes, it will pick up the base class' properties too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜