Skip to content

Commit

Permalink
Remove usage of DeepClone
Browse files Browse the repository at this point in the history
DeepClone uses BinaryFormatter which is obsolete in .NET 5.0 and throws a PlatformNotSupportedException.

The fix insures that columns are cloned instead of cloning the whole object

Fixes #479

+semver: fix
  • Loading branch information
hazzik committed Nov 12, 2020
1 parent f3cd57c commit 77b9b7b
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/FluentNHibernate/Mapping/ComponentMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ protected override ComponentMapping CreateComponentMappingRoot(AttributeStore st

ExternalComponentMapping IExternalComponentMappingProvider.GetComponentMapping()
{
var mapping = (ExternalComponentMapping)CreateComponentMapping();

return mapping.DeepClone();
return (ExternalComponentMapping) CreateComponentMapping();
}

Type IExternalComponentMappingProvider.Type
Expand Down
2 changes: 1 addition & 1 deletion src/FluentNHibernate/Mapping/ElementPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ ElementMapping IElementMappingProvider.GetElementMapping()
foreach (var column in Columns)
{
column.MergeAttributes(columnAttributes);
mapping.AddColumn(Layer.Defaults, column);
mapping.AddColumn(Layer.Defaults, column.Clone());
}

return mapping;
Expand Down
2 changes: 1 addition & 1 deletion src/FluentNHibernate/Mapping/JoinedSubClassPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ SubclassMapping ISubclassMappingProvider.GetSubclassMapping()
mapping.Set(x => x.Type, Layer.Defaults, typeof(TSubclass));

foreach (var column in columns)
mapping.Key.AddColumn(Layer.Defaults, column);
mapping.Key.AddColumn(Layer.Defaults, column.Clone());

foreach (var property in providers.Properties)
mapping.AddProperty(property.GetPropertyMapping());
Expand Down
4 changes: 2 additions & 2 deletions src/FluentNHibernate/Mapping/ManyToManyPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ protected override CollectionMapping GetCollectionMapping()
collection.Key.AddColumn(Layer.Defaults, new ColumnMapping(EntityType.Name + "_id"));

foreach (var column in parentKeyColumns)
collection.Key.AddColumn(Layer.UserSupplied, column);
collection.Key.AddColumn(Layer.UserSupplied, column.Clone());

if (collection.Relationship != null)
{
Expand All @@ -379,7 +379,7 @@ protected override CollectionMapping GetCollectionMapping()
((ManyToManyMapping)collection.Relationship).AddColumn(Layer.Defaults, new ColumnMapping(typeof(TChild).Name + "_id"));

foreach (var column in childKeyColumns)
((ManyToManyMapping)collection.Relationship).AddColumn(Layer.UserSupplied, column);
((ManyToManyMapping)collection.Relationship).AddColumn(Layer.UserSupplied, column.Clone());
}

// HACK: Index only on list and map - shouldn't have to do this!
Expand Down
2 changes: 1 addition & 1 deletion src/FluentNHibernate/Mapping/OneToManyPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ protected override CollectionMapping GetCollectionMapping()

foreach (var column in keyColumns)
{
collection.Key.AddColumn(Layer.UserSupplied, column);
collection.Key.AddColumn(Layer.UserSupplied, column.Clone());
}

// HACK: shouldn't have to do this!
Expand Down
2 changes: 1 addition & 1 deletion src/FluentNHibernate/Mapping/PropertyPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ PropertyMapping IPropertyMappingProvider.GetPropertyMapping()
}

foreach (var column in columns)
mapping.AddColumn(Layer.UserSupplied, column);
mapping.AddColumn(Layer.UserSupplied, column.Clone());

foreach (var column in mapping.Columns)
{
Expand Down
2 changes: 1 addition & 1 deletion src/FluentNHibernate/Mapping/SubclassMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ SubclassMapping IIndeterminateSubclassMappingProvider.GetSubclassMapping(Subclas
}
}

return mapping.DeepClone();
return mapping;
}

Type IIndeterminateSubclassMappingProvider.EntityType
Expand Down
1 change: 1 addition & 0 deletions src/FluentNHibernate/Utils/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static bool HasInterface(this Type type, Type interfaceType)
return type.GetInterfaces().Contains(interfaceType);
}

[Obsolete("Please do not use this method. It will be removed in a future version.")]
public static T DeepClone<T>(this T obj)
{
using (var stream = new MemoryStream())
Expand Down

0 comments on commit 77b9b7b

Please sign in to comment.