mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#18826: Preventing shared references to repository collections
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
@@ -111,6 +112,27 @@ namespace Orchard.Data {
|
||||
Logger.Debug("Copy {0} {1}", source, target);
|
||||
var metadata = Session.SessionFactory.GetClassMetadata(typeof (T));
|
||||
var values = metadata.GetPropertyValues(source, EntityMode.Poco);
|
||||
|
||||
for (var index = 0; index < values.Length; index++) {
|
||||
var value = values[index];
|
||||
if (value == null)
|
||||
continue;
|
||||
|
||||
var type = value.GetType();
|
||||
var isGenericList = type.GetInterfaces()
|
||||
.Where(i => i.IsGenericType)
|
||||
.Any(i => i.GetGenericTypeDefinition() == typeof(IList<>));
|
||||
|
||||
if(!isGenericList)
|
||||
continue;
|
||||
|
||||
var genericType = type.GetGenericArguments().First();
|
||||
var makeGenericType = typeof (List<>).MakeGenericType(new[] {genericType});
|
||||
|
||||
var listValues = ((IList)value);
|
||||
values[index] = Activator.CreateInstance(makeGenericType, new[] { listValues });
|
||||
}
|
||||
|
||||
metadata.SetPropertyValues(target, values, EntityMode.Poco);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user