I would like to create a method that receive 3 strings as parameter and return an object that contains three properties that they referred to these Strings.
Do not have an "old Object" to replicate. The properties should be created in this method.
Is to do this in C # with reflection? If so, how? Below is what you like and I am not able to do.
protected Object getNewObject(String name, String phone, String email)
{
Object newObject = new Object();
... //I can not add the variables that received by the object parameter here.
return newObject();
}
If you want to add properties, fields etc. in dynamic, you may try using Expando class
http://msdn.microsoft.com/en-us/library/system.dynamic.expandoobject.aspx
dynamic newObject = new ExpandoObject();
newObject.name = name;
newObject.phone = phone;
newObject.email = email
protected dynamic getNewObject(String name, String phone, String email)
{
return new { name = name, phone = phone, email = email };
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With