开发者

ASP.NET Reflection get typeof current object

开发者 https://www.devze.com 2023-01-02 09:59 出处:网络
I am working on a project where all of our object have a standard base class. We just added some new fields to the database for the tables behind some of the objects e.g. \"DateCreated\".

I am working on a project where all of our object have a standard base class. We just added some new fields to the database for the tables behind some of the objects e.g. "DateCreated".

I would like to use reflection on the base class' insert method so that when it is called it checks the object to see if it has a property "DateCreated" and if it does sets it to DateTime.Now

The problem I'm having is typeof(this) does not work and I don't know what the type is in the base class obviously.

Is i开发者_如何学Got possible to get the PropertyInfo typeof for an object from within the object without hard coding the object type or using a generic?


You can use this.GetType() in the base and receive the Type of the derived class.

0

精彩评论

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

关注公众号