Skip to content

Cleanup serialization #1469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/NHibernate/AdoNet/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public void FlushEnding()

#region Serialization

private ConnectionManager(SerializationInfo info, StreamingContext context)
protected ConnectionManager(SerializationInfo info, StreamingContext context)
{
_ownConnection = info.GetBoolean("ownConnection");
Session = (ISessionImplementor)info.GetValue("session", typeof(ISessionImplementor));
Expand All @@ -365,7 +365,7 @@ private ConnectionManager(SerializationInfo info, StreamingContext context)
}

[SecurityCritical]
public void GetObjectData(SerializationInfo info, StreamingContext context)
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("ownConnection", _ownConnection);
info.AddValue("session", Session, typeof(ISessionImplementor));
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Async/Engine/StatefulPersistenceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace NHibernate.Engine
{
using System.Threading.Tasks;
using System.Threading;
public partial class StatefulPersistenceContext : IPersistenceContext, ISerializable, IDeserializationCallback
public sealed partial class StatefulPersistenceContext : IPersistenceContext, ISerializable, IDeserializationCallback
{

#region IPersistenceContext Members
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.Serialization;
using System.Security;

namespace NHibernate.Bytecode
{
Expand All @@ -13,8 +14,20 @@ public UnableToLoadProxyFactoryFactoryException(string typeName, Exception inner
this.typeName = typeName;
}

protected UnableToLoadProxyFactoryFactoryException(SerializationInfo info,
StreamingContext context) : base(info, context) {}
protected UnableToLoadProxyFactoryFactoryException(
SerializationInfo info,
StreamingContext context) : base(info, context)
{
typeName = info.GetString("typeName");
}

[SecurityCritical]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("typeName", typeName);
}

public override string Message
{
get
Expand All @@ -34,4 +47,4 @@ public override string Message
}
}
}
}
}
7 changes: 5 additions & 2 deletions src/NHibernate/Cfg/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class Configuration : ISerializable
protected IList<IAuxiliaryDatabaseObject> auxiliaryDatabaseObjects;

private INamingStrategy namingStrategy = DefaultNamingStrategy.Instance;

[NonSerialized]
private MappingsQueue mappingsQueue;

private EventListeners eventListeners;
Expand All @@ -80,7 +82,7 @@ public class Configuration : ISerializable
protected internal SettingsFactory settingsFactory;

#region ISerializable Members
public Configuration(SerializationInfo info, StreamingContext context)
protected Configuration(SerializationInfo info, StreamingContext context)
{
Reset();

Expand Down Expand Up @@ -121,7 +123,7 @@ private T GetSerialedObject<T>(SerializationInfo info, string name)
}

[SecurityCritical]
public void GetObjectData(SerializationInfo info, StreamingContext context)
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
ConfigureProxyFactoryFactory();
SecondPassCompile();
Expand Down Expand Up @@ -1889,6 +1891,7 @@ protected virtual string GetDefaultConfigurationFilePath()

#endregion

[NonSerialized]
private XmlSchemas schemas;

private XmlSchemas Schemas
Expand Down
1 change: 0 additions & 1 deletion src/NHibernate/Cfg/Mappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace NHibernate.Cfg
/// A collection of mappings from classes and collections to relational database tables.
/// </summary>
/// <remarks>Represents a single <c>&lt;hibernate-mapping&gt;</c> element.</remarks>
[Serializable]
public class Mappings
{
#region Utility classes
Expand Down
3 changes: 2 additions & 1 deletion src/NHibernate/Context/AsyncLocalSessionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace NHibernate.Context
[Serializable]
public class AsyncLocalSessionContext : CurrentSessionContext
{
[NonSerialized]
private readonly AsyncLocal<ISession> _session = new AsyncLocal<ISession>();

// Constructor signature required for dynamic invocation code.
Expand All @@ -30,4 +31,4 @@ protected override ISession Session
set => _session.Value = value;
}
}
}
}
7 changes: 6 additions & 1 deletion src/NHibernate/Criterion/MatchMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace NHibernate.Criterion
/// <summary>
/// Represents an strategy for matching strings using "like".
/// </summary>
[Serializable]
public abstract class MatchMode
{
private int _intCode;
Expand Down Expand Up @@ -89,6 +90,7 @@ public override string ToString()
/// <summary>
/// The <see cref="MatchMode"/> that matches the entire string to the pattern.
/// </summary>
[Serializable]
private class ExactMatchMode : MatchMode
{
/// <summary>
Expand All @@ -112,6 +114,7 @@ public override string ToMatchString(string pattern)
/// <summary>
/// The <see cref="MatchMode"/> that matches the start of the string to the pattern.
/// </summary>
[Serializable]
private class StartMatchMode : MatchMode
{
/// <summary>
Expand All @@ -135,6 +138,7 @@ public override string ToMatchString(string pattern)
/// <summary>
/// The <see cref="MatchMode"/> that matches the end of the string to the pattern.
/// </summary>
[Serializable]
private class EndMatchMode : MatchMode
{
/// <summary>
Expand All @@ -159,6 +163,7 @@ public override string ToMatchString(string pattern)
/// The <see cref="MatchMode"/> that exactly matches the string
/// by appending "<c>%</c>" to the beginning and end.
/// </summary>
[Serializable]
private class AnywhereMatchMode : MatchMode
{
/// <summary>
Expand All @@ -179,4 +184,4 @@ public override string ToMatchString(string pattern)
}
}
}
}
}
1 change: 1 addition & 0 deletions src/NHibernate/Dialect/Function/SQLFunctionTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class SQLFunctionTemplate : ISQLFunction
private const int InvalidArgumentIndex = -1;
private static readonly Regex SplitRegex = new Regex("(\\?[0-9]+)");

[Serializable]
private struct TemplateChunk
{
public string Text; // including prefix if parameter
Expand Down
15 changes: 13 additions & 2 deletions src/NHibernate/DuplicateMappingException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.Serialization;
using System.Security;

namespace NHibernate
{
Expand Down Expand Up @@ -59,9 +60,19 @@ public DuplicateMappingException(string type, string name)
/// <param name="context">
/// The <see cref="StreamingContext"/> that contains contextual information about the source or destination.
/// </param>
public DuplicateMappingException(SerializationInfo info, StreamingContext context)
protected DuplicateMappingException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
type = info.GetString("type");
name = info.GetString("name");
}

[SecurityCritical]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("type", type);
info.AddValue("name", name);
}
}
}
}
7 changes: 6 additions & 1 deletion src/NHibernate/Engine/CascadeStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public abstract class CascadeStyle : ISerializable
{
/// <summary> package-protected constructor</summary>
internal CascadeStyle() {}

protected CascadeStyle(SerializationInfo info, StreamingContext context)
{
}

static CascadeStyle()
{
Styles["all"] = All;
Expand Down Expand Up @@ -261,7 +266,7 @@ public MultipleCascadeStyle(CascadeStyle[] styles)
this.styles = styles;
}

private MultipleCascadeStyle(SerializationInfo info, StreamingContext context)
private MultipleCascadeStyle(SerializationInfo info, StreamingContext context) : base(info, context)
{
styles = (CascadeStyle[])info.GetValue("styles", typeof(CascadeStyle[]));
}
Expand Down
1 change: 0 additions & 1 deletion src/NHibernate/Engine/Query/NativeSQLQueryPlan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
namespace NHibernate.Engine.Query
{
/// <summary> Defines a query execution plan for a native-SQL query. </summary>
[Serializable]
public partial class NativeSQLQueryPlan
{
private static readonly IInternalLogger log = LoggerProvider.LoggerFor(typeof(NativeSQLQueryPlan));
Expand Down
8 changes: 4 additions & 4 deletions src/NHibernate/Engine/StatefulPersistenceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace NHibernate.Engine
/// PersistentContext to drive their processing.
/// </remarks>
[Serializable]
public partial class StatefulPersistenceContext : IPersistenceContext, ISerializable, IDeserializationCallback
public sealed partial class StatefulPersistenceContext : IPersistenceContext, ISerializable, IDeserializationCallback
{
private const int InitCollectionSize = 8;
private static readonly IInternalLogger log = LoggerProvider.LoggerFor(typeof(StatefulPersistenceContext));
Expand Down Expand Up @@ -790,7 +790,7 @@ public object GetCollectionOwner(object key, ICollectionPersister collectionPers
/// The owner, if its entity ID is available from the collection's loaded key
/// and the owner entity is in the persistence context; otherwise, returns null
/// </returns>
public virtual object GetLoadedCollectionOwnerOrNull(IPersistentCollection collection)
public object GetLoadedCollectionOwnerOrNull(IPersistentCollection collection)
{
CollectionEntry ce = GetCollectionEntry(collection);
if (ce.LoadedPersister == null)
Expand All @@ -811,7 +811,7 @@ public virtual object GetLoadedCollectionOwnerOrNull(IPersistentCollection colle
/// <summary> Get the ID for the entity that owned this persistent collection when it was loaded </summary>
/// <param name="collection">The persistent collection </param>
/// <returns> the owner ID if available from the collection's loaded key; otherwise, returns null </returns>
public virtual object GetLoadedCollectionOwnerIdOrNull(IPersistentCollection collection)
public object GetLoadedCollectionOwnerIdOrNull(IPersistentCollection collection)
{
return GetLoadedCollectionOwnerIdOrNull(GetCollectionEntry(collection));
}
Expand Down Expand Up @@ -1475,7 +1475,7 @@ void IDeserializationCallback.OnDeserialization(object sender)
#endregion

#region ISerializable Members
internal StatefulPersistenceContext(SerializationInfo info, StreamingContext context)
private StatefulPersistenceContext(SerializationInfo info, StreamingContext context)
{
loadCounter = 0;
flushing = false;
Expand Down
3 changes: 1 addition & 2 deletions src/NHibernate/Event/AbstractCollectionEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
namespace NHibernate.Event
{
/// <summary> Defines a base class for events involving collections. </summary>
[Serializable]
public abstract class AbstractCollectionEvent : AbstractEvent
{
private readonly object affectedOwner;
Expand Down Expand Up @@ -108,4 +107,4 @@ public virtual string GetAffectedOwnerEntityName()
return affectedOwnerEntityName;
}
}
}
}
3 changes: 1 addition & 2 deletions src/NHibernate/Event/AbstractEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace NHibernate.Event
/// <summary>
/// Defines a base class for Session generated events.
/// </summary>
[Serializable]
public class AbstractEvent : IDatabaseEventArgs
{
/// <summary>
Expand All @@ -23,4 +22,4 @@ public AbstractEvent(IEventSource source)
/// </summary>
public IEventSource Session { get; private set; }
}
}
}
1 change: 0 additions & 1 deletion src/NHibernate/Event/AbstractPostDatabaseOperationEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace NHibernate.Event
/// <summary>
/// Represents an operation we performed against the database.
/// </summary>
[Serializable]
public class AbstractPostDatabaseOperationEvent : AbstractEvent, IPostDatabaseOperationEventArgs
{
/// <summary> Constructs an event containing the pertinent information. </summary>
Expand Down
3 changes: 1 addition & 2 deletions src/NHibernate/Event/AbstractPreDatabaseOperationEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace NHibernate.Event
/// <summary>
/// Represents an operation we are about to perform against the database.
/// </summary>
[Serializable]
public abstract class AbstractPreDatabaseOperationEvent : AbstractEvent, IPreDatabaseOperationEventArgs
{
/// <summary> Constructs an event containing the pertinent information. </summary>
Expand All @@ -34,4 +33,4 @@ protected AbstractPreDatabaseOperationEvent(IEventSource source, object entity,
/// </summary>
public IEntityPersister Persister { get; private set; }
}
}
}
3 changes: 1 addition & 2 deletions src/NHibernate/Event/AutoFlushEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace NHibernate.Event
{
/// <summary>Defines an event class for the auto-flushing of a session. </summary>
[Serializable]
public class AutoFlushEvent : FlushEvent
{
private ISet<string> querySpaces;
Expand All @@ -28,4 +27,4 @@ public bool FlushRequired
set { flushRequired = value; }
}
}
}
}
3 changes: 1 addition & 2 deletions src/NHibernate/Event/DeleteEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace NHibernate.Event
{
/// <summary>Defines an event class for the deletion of an entity. </summary>
[Serializable]
public class DeleteEvent : AbstractEvent
{
private readonly string entityName;
Expand Down Expand Up @@ -53,4 +52,4 @@ public bool CascadeDeleteEnabled
get { return cascadeDeleteEnabled; }
}
}
}
}
3 changes: 1 addition & 2 deletions src/NHibernate/Event/DirtyCheckEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace NHibernate.Event
{
/// <summary>Defines an event class for the dirty-checking of a session. </summary>
[Serializable]
public class DirtyCheckEvent : FlushEvent
{
public DirtyCheckEvent(IEventSource source) : base(source) { }
Expand All @@ -16,4 +15,4 @@ public bool Dirty
set { dirty = value; }
}
}
}
}
3 changes: 1 addition & 2 deletions src/NHibernate/Event/EvictEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace NHibernate.Event
{
/// <summary> Defines an event class for the evicting of an entity. </summary>
[Serializable]
public class EvictEvent : AbstractEvent
{
private object entity;
Expand All @@ -20,4 +19,4 @@ public object Entity
set { entity = value; }
}
}
}
}
3 changes: 1 addition & 2 deletions src/NHibernate/Event/FlushEntityEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace NHibernate.Event
{
[Serializable]
public class FlushEntityEvent : AbstractEvent
{
private readonly object entity;
Expand Down Expand Up @@ -74,4 +73,4 @@ public bool HasDatabaseSnapshot
get { return databaseSnapshot != null; }
}
}
}
}
Loading