/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="target"></param> public static void MapToObject(object source, object target) { var sourceMembers = KandaDataMapper.GetMembers(source); var targetMembers = KandaDataMapper.GetMembers(target); foreach (var t in targetMembers) { var attributes = (KandaDataMappingAttribute[])t.GetCustomAttributes(typeof(KandaDataMappingAttribute), true); foreach (var s in sourceMembers) { var value = KandaDataMapper.GetValue(s, source); foreach (var attribute in attributes) { if (s.Name != attribute.MappingName) { continue; } KandaDataMapper.SetValue(t, target, value); break; } if (attributes.Any()) { continue; } if (s.Name != t.Name) { continue; } KandaDataMapper.SetValue(t, target, value); break; } } }
/// <summary> /// /// </summary> /// <param name="member"></param> /// <param name="obj"></param> /// <returns></returns> protected static object GetValue(MemberInfo member, object obj) { return(KandaDataMapper.GetValue(member, obj, default(object))); }