public static D ConvertItem<O, D>(O o) where O : class where D : class, new() { D returnValue = new D(); var typeO = typeof(O); var typeD = typeof(D); foreach (var item in typeD.GetProperties()) { var prop = typeO.GetProperty(item.Name); if (!prop.GetGetMethod().IsVirtual) { // NULLABLE PROPERTIES. if (Nullable.GetUnderlyingType(prop.PropertyType) != null) { var columnType = prop.PropertyType.GetGenericArguments()[0]; if (typeO.GetProperty(item.Name).GetValue(o) != null) item.SetValue(returnValue, Convert.ChangeType(typeO.GetProperty(item.Name).GetValue(o), columnType)); } else { // Normal properties. item.SetValue(returnValue, Convert.ChangeType(typeO.GetProperty(item.Name).GetValue(o), item.PropertyType)); } } else { //HERE, I'AM NEED CALL item.SetValue(...) For VIRTUAL PROPERTIE. //HERE I NEED HELP. } }
MethodInfo
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)