|
|
@ -62,14 +62,33 @@ namespace NzbDrone.Api.Mapping
|
|
|
|
|
|
|
|
|
|
|
|
private static object MapLazy(ConventionInfo conventionInfo)
|
|
|
|
private static object MapLazy(ConventionInfo conventionInfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var sourceArgument = conventionInfo.SourceProp.Type.GetGenericArguments()[0];
|
|
|
|
var genericArgument = conventionInfo.SourceProp.Type.GetGenericArguments()[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dynamic lazy = conventionInfo.SourceProp.Value;
|
|
|
|
dynamic lazy = conventionInfo.SourceProp.Value;
|
|
|
|
|
|
|
|
|
|
|
|
if (lazy.IsLoaded && conventionInfo.TargetProp.Type.IsAssignableFrom(genericArgument))
|
|
|
|
if (lazy.IsLoaded)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return lazy.Value;
|
|
|
|
if (conventionInfo.TargetProp.Type.IsAssignableFrom(sourceArgument))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return lazy.Value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var genericArgument = conventionInfo.TargetProp.Type;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (genericArgument.IsValueType || genericArgument == typeof(string))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return lazy.Value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (genericArgument.IsGenericType)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (conventionInfo.SourceProp.Type.GetGenericTypeDefinition().GetInterfaces().Any(d => d == typeof(IEnumerable)))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return MapLists(genericArgument, lazy.Value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Activator.CreateInstance(genericArgument).InjectFrom((object)lazy.Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
@ -78,25 +97,29 @@ namespace NzbDrone.Api.Mapping
|
|
|
|
private static object MapLists(ConventionInfo conventionInfo)
|
|
|
|
private static object MapLists(ConventionInfo conventionInfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var genericArgument = conventionInfo.TargetProp.Type.GetGenericArguments()[0];
|
|
|
|
var genericArgument = conventionInfo.TargetProp.Type.GetGenericArguments()[0];
|
|
|
|
if (genericArgument.IsValueType || genericArgument == typeof(string))
|
|
|
|
|
|
|
|
|
|
|
|
return MapLists(genericArgument, conventionInfo.SourceProp.Value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static object MapLists(Type targetType, object sourceValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (targetType.IsValueType || targetType == typeof(string))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return conventionInfo.SourceProp.Value;
|
|
|
|
return sourceValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var listType = typeof(List<>).MakeGenericType(targetType);
|
|
|
|
var listType = typeof(List<>).MakeGenericType(genericArgument);
|
|
|
|
|
|
|
|
var addMethod = listType.GetMethod("Add");
|
|
|
|
var addMethod = listType.GetMethod("Add");
|
|
|
|
|
|
|
|
|
|
|
|
var result = Activator.CreateInstance(listType);
|
|
|
|
var result = Activator.CreateInstance(listType);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var sourceItem in (IEnumerable)conventionInfo.SourceProp.Value)
|
|
|
|
foreach (var sourceItem in (IEnumerable)sourceValue)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var e = Activator.CreateInstance(genericArgument).InjectFrom<CloneInjection>(sourceItem);
|
|
|
|
var e = Activator.CreateInstance(targetType).InjectFrom<CloneInjection>(sourceItem);
|
|
|
|
addMethod.Invoke(result, new[] {e });
|
|
|
|
addMethod.Invoke(result, new[] { e });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|