Chris Straw
SHARE:

Copy Property Values using Reflection

Spread the love
			System.Reflection.PropertyInfo[] properties = typeof(T).GetProperties();
			foreach (System.Reflection.PropertyInfo property in properties)
			{
				System.Reflection.PropertyInfo setProperty = toObject.GetType().GetProperty(property.Name);
				if (setProperty != null)
				{
					setProperty.SetValue(toObject, property.GetValue(fromObject, null), null);
				}
				
			}