I have a class named BackUp
that contains a few properties.
Let's say I have an existing instance of BackUp
with its properties initialized.
As I use reflection in the BackUp
class where I want to create an AgentActivator
object and I need to set its properties, the idea is to retrieve the properties from the BackUp
object.
The problem is to take PropertyInfo
object from the BackUp
object and set the matching property on the reflected object.
I am doing the following:
Assembly assembly = Assembly.LoadFile(localBackUp.AssemblyFileName);
Type currentClasstype = assembly.GetType(localBackUp.ClassName);
PropertyInfo[] properties = currentClasstype.GetProperties();
object classInstance = Activator.CreateInstance(localBackUp.AssemblyFileName,
localBackUp.ClassName);
string propName= null;
foreach(PropertyInfo prop in properties)
{
propName= prop.Name;
currentClasstype.GetProperty(propName).
SetValue(classInstance, findProperty(localBackUp, propNmae), null);
}
I need to find a way to implement the findProperty
Method.
Its job is to get the string (property name) and return the matching value from the localBackUp
which holds property with the propName
.