How can deserialize one class to another class like this:
var ser = SerializedObject(b);// read from Database!
var des = DeSerializeAnObject(ser, typeof(BaseClass));
BaseClass baseclass = (BaseClass)des;
baseclass.Hello();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Are you sure it’s really serialization/deserialization you’re after? Sounds to me like what you’re looking for is code to map (ie copy selected or all properties) one object to another.
Have a look at the AutoMapper Getting Started Guide.
In following with your example you could do something like this
I’m also somewhat confused with your choice of class names in your example. If “BaseClass” really is a base class of OtherClass then you’d just do a cast instead but I’m going to guess that’s not the case.