I have the following code:
List<MultiServiceRequestMember> _memberList = new List<MultiServiceRequestMember>();
var type = Type.GetType(svc.NotificationClassName); <- this is a string of the class name.
MultiServiceRequestMember newMember = (MultiServiceRequestMember)Activator.CreateInstance(type);
_memberList.add(newMember);
The MultServiceRequestMember is a base type and I want to assign values to properties specific to type. My question is: How do I cast newMember to type and access its properties?
You can’t cast it, because you don’t know the specific type at compile-time. If you did, you wouldn’t need reflection in the first place!
You’ll have to set the properties by reflection too: