ModelFactory.cs 563 Bytes
using System.Reflection;
using System;

namespace News_site.helpers
{
	public class ModelFactory<PClass, CClass>
		where PClass : class
		where CClass : class
	{

		public static CClass CloneObject(CClass a, PClass parent)
		{
			try
			{
				foreach (PropertyInfo prop in parent.GetType().GetProperties())
				{
					var propFound = a.GetType().GetProperty(prop.Name);
					if (propFound != null)
					{
						propFound.SetValue(a, prop.GetValue(parent, null), null);
					}

				}
				return a;
			}
			catch (Exception ex)
			{
				throw ex;
			}

		}
	}
}