You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
547 B
16 lines
547 B
internal static class BaseControllerHelpers
|
|
{
|
|
public static TEditDto ConvertToEntity<TEditDto>(object obj) where TEditDto : new()
|
|
{
|
|
TEditDto entity = new TEditDto();
|
|
foreach (var property in typeof(TEditDto).GetProperties())
|
|
{
|
|
var value = obj.GetType().GetProperty(property.Name)?.GetValue(obj, null);
|
|
if (value != null)
|
|
{
|
|
property.SetValue(entity, Convert.ChangeType(value, property.PropertyType), null);
|
|
}
|
|
}
|
|
return entity;
|
|
}
|
|
} |