23 lines
820 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using UserService.Infrastructure.DataModels;
namespace UserService.Infrastructure
{
public static class NodeExtensions
{
public static void MapFields(this User user, Dictionary<string, object> values)
{
if (user == null) throw new ArgumentNullException(nameof(user));
if (values == null) throw new ArgumentNullException(nameof(values));
var properties = user.GetType().GetProperties();
foreach (var keyValuePair in values)
{
var propertyInfo = properties.FirstOrDefault(x => x.Name == keyValuePair.Key);
if (propertyInfo == null) continue;
propertyInfo.SetValue(user, keyValuePair.Value);
}
}
}
}