Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Patch 4 #159

Open
wants to merge 2 commits into from

2 participants

@CV1

Fixed issues in mono (2.10) with BinaryFormatter

CV1 added some commits
@CV1 CV1 Update src/FluentNHibernate/Utils/Extensions.cs
Added a lock in DeepClone methode because mono has synchronization issue with the BinaryFormatter
a1f3c73
@CV1 CV1 Update src/FluentNHibernate/MappingModel/Collections/AttributeLayered…
…Values.cs

fixed mono (2.10) issue with BinaryFormatter:
OnDeserialization is not called in mono for fields of type Dictionary
5a44395
@jagregory
Owner

This request also doesn't pass all specs for the same reason as #156

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 15, 2012
  1. @CV1

    Update src/FluentNHibernate/Utils/Extensions.cs

    CV1 authored
    Added a lock in DeepClone methode because mono has synchronization issue with the BinaryFormatter
  2. @CV1

    Update src/FluentNHibernate/MappingModel/Collections/AttributeLayered…

    CV1 authored
    …Values.cs
    
    fixed mono (2.10) issue with BinaryFormatter:
    OnDeserialization is not called in mono for fields of type Dictionary
This page is out of date. Refresh to see the latest.
View
26 src/FluentNHibernate/MappingModel/Collections/AttributeLayeredValues.cs
@@ -1,13 +1,28 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.Serialization;
+
namespace FluentNHibernate.MappingModel.Collections
{
[Serializable]
- public class AttributeLayeredValues
+ public class AttributeLayeredValues : ISerializable
{
- readonly Dictionary<string, LayeredValues> inner = new Dictionary<string, LayeredValues>();
+ readonly Dictionary<string, LayeredValues> inner;
+
+ public AttributeLayeredValues()
+ {
+ inner = new Dictionary<string, LayeredValues>();
+ }
+
+ public AttributeLayeredValues(SerializationInfo info, StreamingContext context)
+ {
+ inner = (Dictionary<string, LayeredValues>)info
+ .GetValue("inner", typeof(Dictionary<string, LayeredValues>));
+ inner.OnDeserialization(this);
+ }
+
public LayeredValues this[string attribute]
{
@@ -90,5 +105,10 @@ public override int GetHashCode()
return hashCode;
}
+ public void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ info.AddValue("inner", inner);
+ }
+
}
}
View
22 src/FluentNHibernate/Utils/Extensions.cs
@@ -64,17 +64,21 @@ public static bool HasInterface(this Type type, Type interfaceType)
return type.GetInterfaces().Contains(interfaceType);
}
+ private readonly static object FormatterLock = new object();
public static T DeepClone<T>(this T obj)
{
- using (var stream = new MemoryStream())
- {
- var formatter = new BinaryFormatter();
-
- formatter.Serialize(stream, obj);
- stream.Position = 0;
-
- return (T)formatter.Deserialize(stream);
- }
+ lock (FormatterLock)
+ {
+ using (var stream = new MemoryStream())
+ {
+ var formatter = new BinaryFormatter();
+
+ formatter.Serialize(stream, obj);
+ stream.Position = 0;
+
+ return (T)formatter.Deserialize(stream);
+ }
+ }
}
public static bool IsAutoMappingOverrideType(this Type type)
Something went wrong with that request. Please try again.