diff --git a/src/NHibernate/AdoNet/ConnectionManager.cs b/src/NHibernate/AdoNet/ConnectionManager.cs index e9881c737fd..4a26a020761 100644 --- a/src/NHibernate/AdoNet/ConnectionManager.cs +++ b/src/NHibernate/AdoNet/ConnectionManager.cs @@ -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)); @@ -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)); diff --git a/src/NHibernate/Async/Engine/StatefulPersistenceContext.cs b/src/NHibernate/Async/Engine/StatefulPersistenceContext.cs index 4a019783423..aba441a5ccb 100644 --- a/src/NHibernate/Async/Engine/StatefulPersistenceContext.cs +++ b/src/NHibernate/Async/Engine/StatefulPersistenceContext.cs @@ -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 diff --git a/src/NHibernate/Bytecode/UnableToLoadProxyFactoryFactoryException.cs b/src/NHibernate/Bytecode/UnableToLoadProxyFactoryFactoryException.cs index d432c6310b2..94db1f6382b 100644 --- a/src/NHibernate/Bytecode/UnableToLoadProxyFactoryFactoryException.cs +++ b/src/NHibernate/Bytecode/UnableToLoadProxyFactoryFactoryException.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.Serialization; +using System.Security; namespace NHibernate.Bytecode { @@ -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 @@ -34,4 +47,4 @@ public override string Message } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Cfg/Configuration.cs b/src/NHibernate/Cfg/Configuration.cs index b209b6d201e..00ba98c238c 100644 --- a/src/NHibernate/Cfg/Configuration.cs +++ b/src/NHibernate/Cfg/Configuration.cs @@ -67,6 +67,8 @@ public class Configuration : ISerializable protected IList auxiliaryDatabaseObjects; private INamingStrategy namingStrategy = DefaultNamingStrategy.Instance; + + [NonSerialized] private MappingsQueue mappingsQueue; private EventListeners eventListeners; @@ -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(); @@ -121,7 +123,7 @@ private T GetSerialedObject(SerializationInfo info, string name) } [SecurityCritical] - public void GetObjectData(SerializationInfo info, StreamingContext context) + public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { ConfigureProxyFactoryFactory(); SecondPassCompile(); @@ -1889,6 +1891,7 @@ protected virtual string GetDefaultConfigurationFilePath() #endregion + [NonSerialized] private XmlSchemas schemas; private XmlSchemas Schemas diff --git a/src/NHibernate/Cfg/Mappings.cs b/src/NHibernate/Cfg/Mappings.cs index ac1ab902233..8d71580157a 100644 --- a/src/NHibernate/Cfg/Mappings.cs +++ b/src/NHibernate/Cfg/Mappings.cs @@ -11,7 +11,6 @@ namespace NHibernate.Cfg /// A collection of mappings from classes and collections to relational database tables. /// /// Represents a single <hibernate-mapping> element. - [Serializable] public class Mappings { #region Utility classes diff --git a/src/NHibernate/Context/AsyncLocalSessionContext.cs b/src/NHibernate/Context/AsyncLocalSessionContext.cs index f1ced4059c2..4da79af0c44 100644 --- a/src/NHibernate/Context/AsyncLocalSessionContext.cs +++ b/src/NHibernate/Context/AsyncLocalSessionContext.cs @@ -19,6 +19,7 @@ namespace NHibernate.Context [Serializable] public class AsyncLocalSessionContext : CurrentSessionContext { + [NonSerialized] private readonly AsyncLocal _session = new AsyncLocal(); // Constructor signature required for dynamic invocation code. @@ -30,4 +31,4 @@ protected override ISession Session set => _session.Value = value; } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Criterion/MatchMode.cs b/src/NHibernate/Criterion/MatchMode.cs index c83f4031ff5..fdb91473e60 100644 --- a/src/NHibernate/Criterion/MatchMode.cs +++ b/src/NHibernate/Criterion/MatchMode.cs @@ -6,6 +6,7 @@ namespace NHibernate.Criterion /// /// Represents an strategy for matching strings using "like". /// + [Serializable] public abstract class MatchMode { private int _intCode; @@ -89,6 +90,7 @@ public override string ToString() /// /// The that matches the entire string to the pattern. /// + [Serializable] private class ExactMatchMode : MatchMode { /// @@ -112,6 +114,7 @@ public override string ToMatchString(string pattern) /// /// The that matches the start of the string to the pattern. /// + [Serializable] private class StartMatchMode : MatchMode { /// @@ -135,6 +138,7 @@ public override string ToMatchString(string pattern) /// /// The that matches the end of the string to the pattern. /// + [Serializable] private class EndMatchMode : MatchMode { /// @@ -159,6 +163,7 @@ public override string ToMatchString(string pattern) /// The that exactly matches the string /// by appending "%" to the beginning and end. /// + [Serializable] private class AnywhereMatchMode : MatchMode { /// @@ -179,4 +184,4 @@ public override string ToMatchString(string pattern) } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Dialect/Function/SQLFunctionTemplate.cs b/src/NHibernate/Dialect/Function/SQLFunctionTemplate.cs index 0c2c9156ea2..b7e8c455e38 100644 --- a/src/NHibernate/Dialect/Function/SQLFunctionTemplate.cs +++ b/src/NHibernate/Dialect/Function/SQLFunctionTemplate.cs @@ -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 diff --git a/src/NHibernate/DuplicateMappingException.cs b/src/NHibernate/DuplicateMappingException.cs index 415c3bfe2bf..58b6e64257a 100644 --- a/src/NHibernate/DuplicateMappingException.cs +++ b/src/NHibernate/DuplicateMappingException.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.Serialization; +using System.Security; namespace NHibernate { @@ -59,9 +60,19 @@ public DuplicateMappingException(string type, string name) /// /// The that contains contextual information about the source or destination. /// - 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); } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Engine/CascadeStyle.cs b/src/NHibernate/Engine/CascadeStyle.cs index 47c60033516..62db17854b7 100644 --- a/src/NHibernate/Engine/CascadeStyle.cs +++ b/src/NHibernate/Engine/CascadeStyle.cs @@ -13,6 +13,11 @@ public abstract class CascadeStyle : ISerializable { /// package-protected constructor internal CascadeStyle() {} + + protected CascadeStyle(SerializationInfo info, StreamingContext context) + { + } + static CascadeStyle() { Styles["all"] = All; @@ -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[])); } diff --git a/src/NHibernate/Engine/Query/NativeSQLQueryPlan.cs b/src/NHibernate/Engine/Query/NativeSQLQueryPlan.cs index 2037c1d1d60..6da2abbcc41 100644 --- a/src/NHibernate/Engine/Query/NativeSQLQueryPlan.cs +++ b/src/NHibernate/Engine/Query/NativeSQLQueryPlan.cs @@ -20,7 +20,6 @@ namespace NHibernate.Engine.Query { /// Defines a query execution plan for a native-SQL query. - [Serializable] public partial class NativeSQLQueryPlan { private static readonly IInternalLogger log = LoggerProvider.LoggerFor(typeof(NativeSQLQueryPlan)); diff --git a/src/NHibernate/Engine/StatefulPersistenceContext.cs b/src/NHibernate/Engine/StatefulPersistenceContext.cs index 0c47bcb8ba0..6c9bd45005d 100644 --- a/src/NHibernate/Engine/StatefulPersistenceContext.cs +++ b/src/NHibernate/Engine/StatefulPersistenceContext.cs @@ -27,7 +27,7 @@ namespace NHibernate.Engine /// PersistentContext to drive their processing. /// [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)); @@ -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 /// - public virtual object GetLoadedCollectionOwnerOrNull(IPersistentCollection collection) + public object GetLoadedCollectionOwnerOrNull(IPersistentCollection collection) { CollectionEntry ce = GetCollectionEntry(collection); if (ce.LoadedPersister == null) @@ -811,7 +811,7 @@ public virtual object GetLoadedCollectionOwnerOrNull(IPersistentCollection colle /// Get the ID for the entity that owned this persistent collection when it was loaded /// The persistent collection /// the owner ID if available from the collection's loaded key; otherwise, returns null - public virtual object GetLoadedCollectionOwnerIdOrNull(IPersistentCollection collection) + public object GetLoadedCollectionOwnerIdOrNull(IPersistentCollection collection) { return GetLoadedCollectionOwnerIdOrNull(GetCollectionEntry(collection)); } @@ -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; diff --git a/src/NHibernate/Event/AbstractCollectionEvent.cs b/src/NHibernate/Event/AbstractCollectionEvent.cs index 15bdfed0226..83749194c7b 100644 --- a/src/NHibernate/Event/AbstractCollectionEvent.cs +++ b/src/NHibernate/Event/AbstractCollectionEvent.cs @@ -6,7 +6,6 @@ namespace NHibernate.Event { /// Defines a base class for events involving collections. - [Serializable] public abstract class AbstractCollectionEvent : AbstractEvent { private readonly object affectedOwner; @@ -108,4 +107,4 @@ public virtual string GetAffectedOwnerEntityName() return affectedOwnerEntityName; } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/AbstractEvent.cs b/src/NHibernate/Event/AbstractEvent.cs index ccf36ce9cba..7e5a0e54ec4 100644 --- a/src/NHibernate/Event/AbstractEvent.cs +++ b/src/NHibernate/Event/AbstractEvent.cs @@ -5,7 +5,6 @@ namespace NHibernate.Event /// /// Defines a base class for Session generated events. /// - [Serializable] public class AbstractEvent : IDatabaseEventArgs { /// @@ -23,4 +22,4 @@ public AbstractEvent(IEventSource source) /// public IEventSource Session { get; private set; } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/AbstractPostDatabaseOperationEvent.cs b/src/NHibernate/Event/AbstractPostDatabaseOperationEvent.cs index 6ce07c7c8db..2dd02e6e0f5 100644 --- a/src/NHibernate/Event/AbstractPostDatabaseOperationEvent.cs +++ b/src/NHibernate/Event/AbstractPostDatabaseOperationEvent.cs @@ -6,7 +6,6 @@ namespace NHibernate.Event /// /// Represents an operation we performed against the database. /// - [Serializable] public class AbstractPostDatabaseOperationEvent : AbstractEvent, IPostDatabaseOperationEventArgs { /// Constructs an event containing the pertinent information. diff --git a/src/NHibernate/Event/AbstractPreDatabaseOperationEvent.cs b/src/NHibernate/Event/AbstractPreDatabaseOperationEvent.cs index 0feef78cedb..6bad7eafb9d 100644 --- a/src/NHibernate/Event/AbstractPreDatabaseOperationEvent.cs +++ b/src/NHibernate/Event/AbstractPreDatabaseOperationEvent.cs @@ -7,7 +7,6 @@ namespace NHibernate.Event /// /// Represents an operation we are about to perform against the database. /// - [Serializable] public abstract class AbstractPreDatabaseOperationEvent : AbstractEvent, IPreDatabaseOperationEventArgs { /// Constructs an event containing the pertinent information. @@ -34,4 +33,4 @@ protected AbstractPreDatabaseOperationEvent(IEventSource source, object entity, /// public IEntityPersister Persister { get; private set; } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/AutoFlushEvent.cs b/src/NHibernate/Event/AutoFlushEvent.cs index f3d052f9c4d..9a37cf51e9e 100644 --- a/src/NHibernate/Event/AutoFlushEvent.cs +++ b/src/NHibernate/Event/AutoFlushEvent.cs @@ -4,7 +4,6 @@ namespace NHibernate.Event { /// Defines an event class for the auto-flushing of a session. - [Serializable] public class AutoFlushEvent : FlushEvent { private ISet querySpaces; @@ -28,4 +27,4 @@ public bool FlushRequired set { flushRequired = value; } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/DeleteEvent.cs b/src/NHibernate/Event/DeleteEvent.cs index cbd53960cce..035bb8a48da 100644 --- a/src/NHibernate/Event/DeleteEvent.cs +++ b/src/NHibernate/Event/DeleteEvent.cs @@ -3,7 +3,6 @@ namespace NHibernate.Event { /// Defines an event class for the deletion of an entity. - [Serializable] public class DeleteEvent : AbstractEvent { private readonly string entityName; @@ -53,4 +52,4 @@ public bool CascadeDeleteEnabled get { return cascadeDeleteEnabled; } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/DirtyCheckEvent.cs b/src/NHibernate/Event/DirtyCheckEvent.cs index 2c37e04f3e5..6d85501b2ec 100644 --- a/src/NHibernate/Event/DirtyCheckEvent.cs +++ b/src/NHibernate/Event/DirtyCheckEvent.cs @@ -3,7 +3,6 @@ namespace NHibernate.Event { /// Defines an event class for the dirty-checking of a session. - [Serializable] public class DirtyCheckEvent : FlushEvent { public DirtyCheckEvent(IEventSource source) : base(source) { } @@ -16,4 +15,4 @@ public bool Dirty set { dirty = value; } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/EvictEvent.cs b/src/NHibernate/Event/EvictEvent.cs index 6ff99e5e462..343d021ebb1 100644 --- a/src/NHibernate/Event/EvictEvent.cs +++ b/src/NHibernate/Event/EvictEvent.cs @@ -3,7 +3,6 @@ namespace NHibernate.Event { /// Defines an event class for the evicting of an entity. - [Serializable] public class EvictEvent : AbstractEvent { private object entity; @@ -20,4 +19,4 @@ public object Entity set { entity = value; } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/FlushEntityEvent.cs b/src/NHibernate/Event/FlushEntityEvent.cs index 46398e94f3f..35e4bb6a583 100644 --- a/src/NHibernate/Event/FlushEntityEvent.cs +++ b/src/NHibernate/Event/FlushEntityEvent.cs @@ -3,7 +3,6 @@ namespace NHibernate.Event { - [Serializable] public class FlushEntityEvent : AbstractEvent { private readonly object entity; @@ -74,4 +73,4 @@ public bool HasDatabaseSnapshot get { return databaseSnapshot != null; } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/FlushEvent.cs b/src/NHibernate/Event/FlushEvent.cs index bb9b7fa4743..995fb2e106a 100644 --- a/src/NHibernate/Event/FlushEvent.cs +++ b/src/NHibernate/Event/FlushEvent.cs @@ -3,9 +3,8 @@ namespace NHibernate.Event { /// Defines an event class for the flushing of a session. - [Serializable] public class FlushEvent : AbstractEvent { public FlushEvent(IEventSource source) : base(source) { } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/LoadEvent.cs b/src/NHibernate/Event/LoadEvent.cs index e821eab8e68..02fc2739f58 100644 --- a/src/NHibernate/Event/LoadEvent.cs +++ b/src/NHibernate/Event/LoadEvent.cs @@ -3,7 +3,6 @@ namespace NHibernate.Event { /// Defines an event class for the loading of an entity. - [Serializable] public class LoadEvent : AbstractEvent { public static readonly LockMode DefaultLockMode = LockMode.None; @@ -96,4 +95,4 @@ public object Result set { result = value; } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/LockEvent.cs b/src/NHibernate/Event/LockEvent.cs index 86729fb5c4d..c9545806174 100644 --- a/src/NHibernate/Event/LockEvent.cs +++ b/src/NHibernate/Event/LockEvent.cs @@ -7,7 +7,6 @@ namespace NHibernate.Event /// /// Defines an event class for the locking of an entity. /// - [Serializable] public class LockEvent : AbstractEvent { private string entityName; diff --git a/src/NHibernate/Event/MergeEvent.cs b/src/NHibernate/Event/MergeEvent.cs index 8ef15667a50..87818a24385 100644 --- a/src/NHibernate/Event/MergeEvent.cs +++ b/src/NHibernate/Event/MergeEvent.cs @@ -4,7 +4,6 @@ namespace NHibernate.Event /// /// An event class for merge() and saveOrUpdateCopy() /// - [Serializable] public class MergeEvent : AbstractEvent { private object original; diff --git a/src/NHibernate/Event/PostCollectionRecreateEvent.cs b/src/NHibernate/Event/PostCollectionRecreateEvent.cs index f2242282310..85ab16ed6bc 100644 --- a/src/NHibernate/Event/PostCollectionRecreateEvent.cs +++ b/src/NHibernate/Event/PostCollectionRecreateEvent.cs @@ -5,11 +5,10 @@ namespace NHibernate.Event { /// An event that occurs after a collection is recreated - [Serializable] public class PostCollectionRecreateEvent : AbstractCollectionEvent { public PostCollectionRecreateEvent(ICollectionPersister collectionPersister, IPersistentCollection collection, IEventSource source) : base(collectionPersister, collection, source, collection.Owner, GetOwnerIdOrNull(collection.Owner, source)) {} } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/PostCollectionRemoveEvent.cs b/src/NHibernate/Event/PostCollectionRemoveEvent.cs index 2612b5514ac..492f4b31904 100644 --- a/src/NHibernate/Event/PostCollectionRemoveEvent.cs +++ b/src/NHibernate/Event/PostCollectionRemoveEvent.cs @@ -5,11 +5,10 @@ namespace NHibernate.Event { /// An event that occurs after a collection is removed - [Serializable] public class PostCollectionRemoveEvent : AbstractCollectionEvent { public PostCollectionRemoveEvent(ICollectionPersister collectionPersister, IPersistentCollection collection, IEventSource source, object loadedOwner) : base(collectionPersister, collection, source, loadedOwner, GetOwnerIdOrNull(loadedOwner, source)) {} } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/PostCollectionUpdateEvent.cs b/src/NHibernate/Event/PostCollectionUpdateEvent.cs index fd53b11aefd..e50b91976f1 100644 --- a/src/NHibernate/Event/PostCollectionUpdateEvent.cs +++ b/src/NHibernate/Event/PostCollectionUpdateEvent.cs @@ -5,7 +5,6 @@ namespace NHibernate.Event { /// An event that occurs after a collection is updated - [Serializable] public class PostCollectionUpdateEvent : AbstractCollectionEvent { public PostCollectionUpdateEvent(ICollectionPersister collectionPersister, IPersistentCollection collection, @@ -14,4 +13,4 @@ public PostCollectionUpdateEvent(ICollectionPersister collectionPersister, IPers collectionPersister, collection, source, GetLoadedOwnerOrNull(collection, source), GetLoadedOwnerIdOrNull(collection, source)) {} } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/PostDeleteEvent.cs b/src/NHibernate/Event/PostDeleteEvent.cs index bc0d7000269..71f6cdb46f8 100644 --- a/src/NHibernate/Event/PostDeleteEvent.cs +++ b/src/NHibernate/Event/PostDeleteEvent.cs @@ -6,7 +6,6 @@ namespace NHibernate.Event /// /// Occurs after deleting an item from the datastore /// - [Serializable] public class PostDeleteEvent : AbstractPostDatabaseOperationEvent { public PostDeleteEvent(object entity, object id, object[] deletedState, IEntityPersister persister, IEventSource source) diff --git a/src/NHibernate/Event/PostInsertEvent.cs b/src/NHibernate/Event/PostInsertEvent.cs index 0b204516757..ccb9d47228a 100644 --- a/src/NHibernate/Event/PostInsertEvent.cs +++ b/src/NHibernate/Event/PostInsertEvent.cs @@ -6,7 +6,6 @@ namespace NHibernate.Event /// /// Occurs after inserting an item in the datastore /// - [Serializable] public class PostInsertEvent : AbstractPostDatabaseOperationEvent { public PostInsertEvent(object entity, object id, object[] state, IEntityPersister persister, IEventSource source) diff --git a/src/NHibernate/Event/PostLoadEvent.cs b/src/NHibernate/Event/PostLoadEvent.cs index baf3349157e..d53cac7a436 100644 --- a/src/NHibernate/Event/PostLoadEvent.cs +++ b/src/NHibernate/Event/PostLoadEvent.cs @@ -6,7 +6,6 @@ namespace NHibernate.Event /// /// Occurs after an an entity instance is fully loaded. /// - [Serializable] public class PostLoadEvent : AbstractEvent, IPostDatabaseOperationEventArgs { private object entity; diff --git a/src/NHibernate/Event/PostUpdateEvent.cs b/src/NHibernate/Event/PostUpdateEvent.cs index a36ded8c1c4..2e3643b74e6 100644 --- a/src/NHibernate/Event/PostUpdateEvent.cs +++ b/src/NHibernate/Event/PostUpdateEvent.cs @@ -6,7 +6,6 @@ namespace NHibernate.Event /// /// Occurs after the datastore is updated /// - [Serializable] public class PostUpdateEvent : AbstractPostDatabaseOperationEvent { public PostUpdateEvent(object entity, object id, object[] state, object[] oldState, IEntityPersister persister, IEventSource source) diff --git a/src/NHibernate/Event/PreCollectionRecreateEvent.cs b/src/NHibernate/Event/PreCollectionRecreateEvent.cs index 7a9ced648d7..10582ad1c4f 100644 --- a/src/NHibernate/Event/PreCollectionRecreateEvent.cs +++ b/src/NHibernate/Event/PreCollectionRecreateEvent.cs @@ -5,11 +5,10 @@ namespace NHibernate.Event { /// An event that occurs before a collection is recreated - [Serializable] public class PreCollectionRecreateEvent : AbstractCollectionEvent { public PreCollectionRecreateEvent(ICollectionPersister collectionPersister, IPersistentCollection collection, IEventSource source) : base(collectionPersister, collection, source, collection.Owner, GetOwnerIdOrNull(collection.Owner, source)) {} } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/PreCollectionRemoveEvent.cs b/src/NHibernate/Event/PreCollectionRemoveEvent.cs index 331bf905866..2b222a77303 100644 --- a/src/NHibernate/Event/PreCollectionRemoveEvent.cs +++ b/src/NHibernate/Event/PreCollectionRemoveEvent.cs @@ -5,11 +5,10 @@ namespace NHibernate.Event { /// An event that occurs before a collection is removed - [Serializable] public class PreCollectionRemoveEvent : AbstractCollectionEvent { public PreCollectionRemoveEvent(ICollectionPersister collectionPersister, IPersistentCollection collection, IEventSource source, object loadedOwner) : base(collectionPersister, collection, source, loadedOwner, GetOwnerIdOrNull(loadedOwner, source)) {} } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/PreCollectionUpdateEvent.cs b/src/NHibernate/Event/PreCollectionUpdateEvent.cs index a89b86806af..e5d558dde50 100644 --- a/src/NHibernate/Event/PreCollectionUpdateEvent.cs +++ b/src/NHibernate/Event/PreCollectionUpdateEvent.cs @@ -5,7 +5,6 @@ namespace NHibernate.Event { /// An event that occurs before a collection is updated - [Serializable] public class PreCollectionUpdateEvent : AbstractCollectionEvent { public PreCollectionUpdateEvent(ICollectionPersister collectionPersister, IPersistentCollection collection, @@ -14,4 +13,4 @@ public PreCollectionUpdateEvent(ICollectionPersister collectionPersister, IPersi collectionPersister, collection, source, GetLoadedOwnerOrNull(collection, source), GetLoadedOwnerIdOrNull(collection, source)) {} } -} \ No newline at end of file +} diff --git a/src/NHibernate/Event/PreLoadEvent.cs b/src/NHibernate/Event/PreLoadEvent.cs index 28e6da355b0..12174b44dc1 100644 --- a/src/NHibernate/Event/PreLoadEvent.cs +++ b/src/NHibernate/Event/PreLoadEvent.cs @@ -6,7 +6,6 @@ namespace NHibernate.Event /// /// Called before injecting property values into a newly loaded entity instance. /// - [Serializable] public class PreLoadEvent : AbstractEvent, IPreDatabaseOperationEventArgs { private object entity; diff --git a/src/NHibernate/Event/RefreshEvent.cs b/src/NHibernate/Event/RefreshEvent.cs index 0f17cc12ada..f95b968a550 100644 --- a/src/NHibernate/Event/RefreshEvent.cs +++ b/src/NHibernate/Event/RefreshEvent.cs @@ -7,7 +7,6 @@ namespace NHibernate.Event /// /// Defines an event class for the refreshing of an object. /// - [Serializable] public class RefreshEvent : AbstractEvent { private readonly LockMode lockMode= LockMode.Read; diff --git a/src/NHibernate/Event/ReplicateEvent.cs b/src/NHibernate/Event/ReplicateEvent.cs index 4269d136096..7ca373c0ee0 100644 --- a/src/NHibernate/Event/ReplicateEvent.cs +++ b/src/NHibernate/Event/ReplicateEvent.cs @@ -7,7 +7,6 @@ namespace NHibernate.Event /// /// Defines an event class for the replication of an entity. /// - [Serializable] public class ReplicateEvent : AbstractEvent { private string entityName; diff --git a/src/NHibernate/Event/SaveOrUpdateEvent.cs b/src/NHibernate/Event/SaveOrUpdateEvent.cs index 14d27cd7078..b96c6a909ef 100644 --- a/src/NHibernate/Event/SaveOrUpdateEvent.cs +++ b/src/NHibernate/Event/SaveOrUpdateEvent.cs @@ -6,7 +6,6 @@ namespace NHibernate.Event /// /// An event class for saveOrUpdate() /// - [Serializable] public class SaveOrUpdateEvent : AbstractEvent { private object entity; diff --git a/src/NHibernate/Exceptions/ADOConnectionException.cs b/src/NHibernate/Exceptions/ADOConnectionException.cs index 94611a6d5d9..6b59c9ced02 100644 --- a/src/NHibernate/Exceptions/ADOConnectionException.cs +++ b/src/NHibernate/Exceptions/ADOConnectionException.cs @@ -10,7 +10,7 @@ namespace NHibernate.Exceptions [Serializable] public class ADOConnectionException : ADOException { - public ADOConnectionException(SerializationInfo info, StreamingContext context) : base(info, context) {} + protected ADOConnectionException(SerializationInfo info, StreamingContext context) : base(info, context) {} public ADOConnectionException(string message, Exception innerException, string sql) : base(message, innerException, sql) {} public ADOConnectionException(string message, Exception innerException) : base(message, innerException) {} } diff --git a/src/NHibernate/Exceptions/ConstraintViolationException.cs b/src/NHibernate/Exceptions/ConstraintViolationException.cs index cee757168b3..e6e0a667212 100644 --- a/src/NHibernate/Exceptions/ConstraintViolationException.cs +++ b/src/NHibernate/Exceptions/ConstraintViolationException.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.Serialization; +using System.Security; namespace NHibernate.Exceptions { @@ -11,9 +12,6 @@ namespace NHibernate.Exceptions public class ConstraintViolationException : ADOException { private readonly string constraintName; - public ConstraintViolationException(SerializationInfo info, StreamingContext context) - : base(info, context) {} - public ConstraintViolationException(string message, Exception innerException, string sql, string constraintName) : base(message, innerException, sql) { @@ -26,6 +24,19 @@ public ConstraintViolationException(string message, Exception innerException, st this.constraintName = constraintName; } + protected ConstraintViolationException(SerializationInfo info, StreamingContext context) + : base(info, context) + { + this.constraintName = info.GetString("constraintName"); + } + + [SecurityCritical] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + info.AddValue("constraintName", this.constraintName); + } + /// /// Returns the name of the violated constraint, if known. /// diff --git a/src/NHibernate/Exceptions/DataException.cs b/src/NHibernate/Exceptions/DataException.cs index 99357d5e194..b4c803e9ed2 100644 --- a/src/NHibernate/Exceptions/DataException.cs +++ b/src/NHibernate/Exceptions/DataException.cs @@ -11,7 +11,7 @@ namespace NHibernate.Exceptions [Serializable] public class DataException : ADOException { - public DataException(SerializationInfo info, StreamingContext context) : base(info, context) {} + protected DataException(SerializationInfo info, StreamingContext context) : base(info, context) {} public DataException(string message, Exception innerException, string sql) : base(message, innerException, sql) {} public DataException(string message, Exception innerException) : base(message, innerException) {} } diff --git a/src/NHibernate/Exceptions/GenericADOException.cs b/src/NHibernate/Exceptions/GenericADOException.cs index d45e298c3f3..e326722125f 100644 --- a/src/NHibernate/Exceptions/GenericADOException.cs +++ b/src/NHibernate/Exceptions/GenericADOException.cs @@ -11,8 +11,8 @@ public GenericADOException() { } - public GenericADOException(SerializationInfo info, StreamingContext context) : base(info, context) { } + protected GenericADOException(SerializationInfo info, StreamingContext context) : base(info, context) { } public GenericADOException(string message, Exception innerException, string sql) : base(message, innerException, sql) { } public GenericADOException(string message, Exception innerException) : base(message, innerException) { } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Exceptions/LockAcquisitionException.cs b/src/NHibernate/Exceptions/LockAcquisitionException.cs index 58a774b13f6..6f4233d286e 100644 --- a/src/NHibernate/Exceptions/LockAcquisitionException.cs +++ b/src/NHibernate/Exceptions/LockAcquisitionException.cs @@ -10,7 +10,7 @@ namespace NHibernate.Exceptions [Serializable] public class LockAcquisitionException : ADOException { - public LockAcquisitionException(SerializationInfo info, StreamingContext context) : base(info, context) {} + protected LockAcquisitionException(SerializationInfo info, StreamingContext context) : base(info, context) {} public LockAcquisitionException(string message, Exception innerException, string sql) : base(message, innerException, sql) {} public LockAcquisitionException(string message, Exception innerException) : base(message, innerException) {} } diff --git a/src/NHibernate/Exceptions/SQLGrammarException.cs b/src/NHibernate/Exceptions/SQLGrammarException.cs index 29f655daac8..a2317295e97 100644 --- a/src/NHibernate/Exceptions/SQLGrammarException.cs +++ b/src/NHibernate/Exceptions/SQLGrammarException.cs @@ -10,7 +10,7 @@ namespace NHibernate.Exceptions [Serializable] public class SQLGrammarException : ADOException { - public SQLGrammarException(SerializationInfo info, StreamingContext context) : base(info, context) {} + protected SQLGrammarException(SerializationInfo info, StreamingContext context) : base(info, context) {} public SQLGrammarException(string message, Exception innerException, string sql) : base(message, innerException, sql) {} public SQLGrammarException(string message, Exception innerException) : base(message, innerException) {} } diff --git a/src/NHibernate/Exceptions/SqlParseException.cs b/src/NHibernate/Exceptions/SqlParseException.cs index 4cc33828a53..73227a68bec 100644 --- a/src/NHibernate/Exceptions/SqlParseException.cs +++ b/src/NHibernate/Exceptions/SqlParseException.cs @@ -1,13 +1,18 @@ using System; +using System.Runtime.Serialization; namespace NHibernate.Exceptions { - public class SqlParseException : Exception - { + [Serializable] + public class SqlParseException : Exception + { - public SqlParseException(string Message) : base(Message) - { - } + public SqlParseException(string Message) : base(Message) + { + } - } + protected SqlParseException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } } diff --git a/src/NHibernate/Hql/Ast/ANTLR/DetailedSemanticException.cs b/src/NHibernate/Hql/Ast/ANTLR/DetailedSemanticException.cs index 03664765475..4e01696df12 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/DetailedSemanticException.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/DetailedSemanticException.cs @@ -1,7 +1,9 @@ using System; +using System.Runtime.Serialization; namespace NHibernate.Hql.Ast.ANTLR { + [Serializable] public class DetailedSemanticException : SemanticException { public DetailedSemanticException(string message) : base(message) @@ -12,5 +14,9 @@ public DetailedSemanticException(string message, Exception inner) : base(message, inner) { } + + protected DetailedSemanticException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } } } diff --git a/src/NHibernate/Hql/Ast/ANTLR/InvalidPathException.cs b/src/NHibernate/Hql/Ast/ANTLR/InvalidPathException.cs index 4e761196b29..6ca3a9b75c4 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/InvalidPathException.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/InvalidPathException.cs @@ -1,14 +1,22 @@ -namespace NHibernate.Hql.Ast.ANTLR +using System; +using System.Runtime.Serialization; + +namespace NHibernate.Hql.Ast.ANTLR { /// /// Exception thrown when an invalid path is found in a query. /// Author: josh /// Ported by: Steve Strong /// + [Serializable] public class InvalidPathException : SemanticException { public InvalidPathException(string s) : base(s) { } + + protected InvalidPathException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } } } diff --git a/src/NHibernate/Hql/Ast/ANTLR/SemanticException.cs b/src/NHibernate/Hql/Ast/ANTLR/SemanticException.cs index 47959d0cab6..3801f75f917 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/SemanticException.cs +++ b/src/NHibernate/Hql/Ast/ANTLR/SemanticException.cs @@ -1,8 +1,10 @@ using System; +using System.Runtime.Serialization; using Antlr.Runtime; namespace NHibernate.Hql.Ast.ANTLR { + [Serializable] public class SemanticException : QueryException { public SemanticException(string message) : base(message) @@ -13,5 +15,9 @@ public SemanticException(string message, Exception inner) : base(message, inner) { } + + protected SemanticException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } } } diff --git a/src/NHibernate/Hql/QueryExecutionRequestException.cs b/src/NHibernate/Hql/QueryExecutionRequestException.cs index 5b038a5c3e6..c471d5f55ce 100644 --- a/src/NHibernate/Hql/QueryExecutionRequestException.cs +++ b/src/NHibernate/Hql/QueryExecutionRequestException.cs @@ -1,11 +1,17 @@ using System; +using System.Runtime.Serialization; namespace NHibernate.Hql { + [Serializable] public class QueryExecutionRequestException : QueryException { public QueryExecutionRequestException(string message, string queryString) : base(message, queryString) { } + + protected QueryExecutionRequestException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } } -} \ No newline at end of file +} diff --git a/src/NHibernate/InvalidProxyTypeException.cs b/src/NHibernate/InvalidProxyTypeException.cs index 946478379ba..0d939a5ca94 100644 --- a/src/NHibernate/InvalidProxyTypeException.cs +++ b/src/NHibernate/InvalidProxyTypeException.cs @@ -36,7 +36,7 @@ private static string FormatMessage(IEnumerable errors) #region Serialization - public InvalidProxyTypeException(SerializationInfo info, StreamingContext context) + protected InvalidProxyTypeException(SerializationInfo info, StreamingContext context) : base(info, context) { Errors = (ICollection)info.GetValue("errors", typeof(ICollection)); diff --git a/src/NHibernate/LazyInitializationException.cs b/src/NHibernate/LazyInitializationException.cs index 8f08a502fc2..05aec0fa485 100644 --- a/src/NHibernate/LazyInitializationException.cs +++ b/src/NHibernate/LazyInitializationException.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.Serialization; +using System.Security; namespace NHibernate @@ -76,6 +77,16 @@ public LazyInitializationException(string message, Exception innerException) : b /// protected LazyInitializationException(SerializationInfo info, StreamingContext context) : base(info, context) { + EntityName = info.GetString("entityName"); + EntityId = info.GetValue("entityId", typeof(object)); + } + + [SecurityCritical] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + info.AddValue("entityName", EntityName); + info.AddValue("entityId", EntityId, typeof(object)); } } -} \ No newline at end of file +} diff --git a/src/NHibernate/PropertyNotFoundException.cs b/src/NHibernate/PropertyNotFoundException.cs index cc3c0150ce9..7e20c5117ff 100644 --- a/src/NHibernate/PropertyNotFoundException.cs +++ b/src/NHibernate/PropertyNotFoundException.cs @@ -1,5 +1,7 @@ using System; using System.Runtime.Serialization; +using System.Security; +using NHibernate.Util; namespace NHibernate { @@ -9,10 +11,13 @@ namespace NHibernate [Serializable] public class PropertyNotFoundException : MappingException { - private readonly System.Type targetType; + private readonly string targetTypeAssemblyQualifiedName; private readonly string propertyName; private readonly string accessorType; + [NonSerialized] + private System.Type targetType; + /// /// Initializes a new instance of the class, /// used when a property get/set accessor is missing. @@ -27,6 +32,7 @@ public PropertyNotFoundException(System.Type targetType, string propertyName, st )) { this.targetType = targetType; + this.targetTypeAssemblyQualifiedName = targetType?.AssemblyQualifiedName; this.propertyName = propertyName; this.accessorType = accessorType; } @@ -42,6 +48,7 @@ public PropertyNotFoundException(System.Type targetType, string propertyName) propertyName, targetType)) { this.targetType = targetType; + this.targetTypeAssemblyQualifiedName = targetType?.AssemblyQualifiedName; this.propertyName = propertyName; } @@ -50,6 +57,7 @@ public PropertyNotFoundException(string propertyName, string fieldName, System.T )) { this.targetType = targetType; + this.targetTypeAssemblyQualifiedName = targetType?.AssemblyQualifiedName; this.propertyName = propertyName; accessorType = fieldName; } @@ -67,11 +75,28 @@ public PropertyNotFoundException(string propertyName, string fieldName, System.T /// protected PropertyNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { + this.targetTypeAssemblyQualifiedName = info.GetString("targetTypeAssemblyQualifiedName"); + this.propertyName = info.GetString("propertyName"); + this.accessorType = info.GetString("accessorType"); + } + + [SecurityCritical] + public override void GetObjectData(SerializationInfo info, StreamingContext context) + { + base.GetObjectData(info, context); + info.AddValue("targetTypeAssemblyQualifiedName", targetTypeAssemblyQualifiedName); + info.AddValue("propertyName", propertyName); + info.AddValue("accessorType", accessorType); } public System.Type TargetType { - get { return targetType; } + get + { + if (targetType != null || targetTypeAssemblyQualifiedName == null) return targetType; + + return (targetType = ReflectHelper.ClassForFullNameOrNull(targetTypeAssemblyQualifiedName)); + } } public string PropertyName @@ -84,4 +109,4 @@ public string AccessorType get { return accessorType; } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Proxy/DynamicProxy/ProxyObjectReference.cs b/src/NHibernate/Proxy/DynamicProxy/ProxyObjectReference.cs index 4b6f99d2f30..84271f5b7c6 100644 --- a/src/NHibernate/Proxy/DynamicProxy/ProxyObjectReference.cs +++ b/src/NHibernate/Proxy/DynamicProxy/ProxyObjectReference.cs @@ -14,12 +14,12 @@ namespace NHibernate.Proxy.DynamicProxy { [Serializable] - public class ProxyObjectReference : IObjectReference, ISerializable + public sealed class ProxyObjectReference : IObjectReference, ISerializable { private readonly System.Type _baseType; private readonly IProxy _proxy; - protected ProxyObjectReference(SerializationInfo info, StreamingContext context) + private ProxyObjectReference(SerializationInfo info, StreamingContext context) { // Deserialize the base type using its assembly qualified name string qualifiedName = info.GetString("__baseType"); diff --git a/src/NHibernate/SchemaValidationException.cs b/src/NHibernate/SchemaValidationException.cs index f679fa570e7..2d654a07583 100644 --- a/src/NHibernate/SchemaValidationException.cs +++ b/src/NHibernate/SchemaValidationException.cs @@ -1,10 +1,12 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Runtime.Serialization; using System.Security; namespace NHibernate { + [Serializable] public class SchemaValidationException : HibernateException { public ReadOnlyCollection ValidationErrors { get; } diff --git a/src/NHibernate/SqlCommand/SqlStringBuilder.cs b/src/NHibernate/SqlCommand/SqlStringBuilder.cs index 6bcc4325aec..1780c60015c 100644 --- a/src/NHibernate/SqlCommand/SqlStringBuilder.cs +++ b/src/NHibernate/SqlCommand/SqlStringBuilder.cs @@ -29,10 +29,11 @@ namespace NHibernate.SqlCommand /// to make sure the correct sql is getting built are specific to MsSql2000Dialect. /// /// + [Serializable] public class SqlStringBuilder : ISqlStringBuilder { // this holds the strings and parameters that make up the full sql statement. - private List sqlParts; + private readonly List sqlParts; private AddingSqlStringVisitor addingVisitor; @@ -321,9 +322,10 @@ public override string ToString() return ToSqlString().ToString(); } + [Serializable] private class AddingSqlStringVisitor : ISqlStringVisitor { - private SqlStringBuilder parent; + private readonly SqlStringBuilder parent; public AddingSqlStringVisitor(SqlStringBuilder parent) { diff --git a/src/NHibernate/Tuple/Entity/EntityMetamodel.cs b/src/NHibernate/Tuple/Entity/EntityMetamodel.cs index 93523caff24..53b820b3715 100644 --- a/src/NHibernate/Tuple/Entity/EntityMetamodel.cs +++ b/src/NHibernate/Tuple/Entity/EntityMetamodel.cs @@ -11,7 +11,6 @@ namespace NHibernate.Tuple.Entity { - [Serializable] public class EntityMetamodel { private static readonly IInternalLogger log = LoggerProvider.LoggerFor(typeof(EntityMetamodel)); diff --git a/src/NHibernate/Tuple/IdentifierProperty.cs b/src/NHibernate/Tuple/IdentifierProperty.cs index 345ed50551f..415d4f36f1d 100644 --- a/src/NHibernate/Tuple/IdentifierProperty.cs +++ b/src/NHibernate/Tuple/IdentifierProperty.cs @@ -12,7 +12,6 @@ namespace NHibernate.Tuple /// /// Author: Steve Ebersole /// - [Serializable] public class IdentifierProperty : Property { private readonly bool isVirtual; @@ -99,4 +98,4 @@ public bool HasIdentifierMapper get { return hasIdentifierMapper; } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Tuple/Property.cs b/src/NHibernate/Tuple/Property.cs index a3d5c0ec2a6..8e0f32902ec 100644 --- a/src/NHibernate/Tuple/Property.cs +++ b/src/NHibernate/Tuple/Property.cs @@ -6,7 +6,6 @@ namespace NHibernate.Tuple /// /// Defines the basic contract of a Property within the runtime metamodel. /// - [Serializable] public abstract class Property { private readonly string name; @@ -38,4 +37,4 @@ public override string ToString() return "Property(" + name + ':' + type.Name + ')'; } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Tuple/VersionProperty.cs b/src/NHibernate/Tuple/VersionProperty.cs index f27ec372b4a..57392e0d706 100644 --- a/src/NHibernate/Tuple/VersionProperty.cs +++ b/src/NHibernate/Tuple/VersionProperty.cs @@ -10,7 +10,6 @@ namespace NHibernate.Tuple /// /// Author: Steve Ebersole /// - [Serializable] public class VersionProperty : StandardProperty { private readonly VersionValue unsavedValue; @@ -58,4 +57,4 @@ public VersionValue UnsavedValue get { return unsavedValue; } } } -} \ No newline at end of file +} diff --git a/src/NHibernate/Util/ReflectHelper.cs b/src/NHibernate/Util/ReflectHelper.cs index 2561323ac91..37c22aa7b7f 100644 --- a/src/NHibernate/Util/ReflectHelper.cs +++ b/src/NHibernate/Util/ReflectHelper.cs @@ -325,7 +325,7 @@ public static System.Type ClassForName(string name) /// the method try to find the System.Type scanning all Assemblies of the . /// /// If no System.Type was found for . - public static System.Type ClassForFullName(string classFullName) + public static System.Type ClassForFullName(string classFullName) { var result = ClassForFullNameOrNull(classFullName); if (result == null) @@ -338,38 +338,40 @@ public static System.Type ClassForFullName(string classFullName) } /// - /// Load a System.Type given its name. - /// - /// The class FullName or AssemblyQualifiedName - /// The System.Type or null - /// - /// If the don't represent an - /// the method try to find the System.Type scanning all Assemblies of the . - /// - public static System.Type ClassForFullNameOrNull(string classFullName) + /// Load a System.Type given its name. + /// + /// The class FullName or AssemblyQualifiedName + /// The System.Type or null + /// + /// If the don't represent an + /// the method try to find the System.Type scanning all Assemblies of the . + /// + public static System.Type ClassForFullNameOrNull(string classFullName) + { + System.Type result = null; + AssemblyQualifiedTypeName parsedName = TypeNameParser.Parse(classFullName); + if (!string.IsNullOrEmpty(parsedName.Assembly)) + { + result = TypeFromAssembly(parsedName, false); + } + else + { + if (!string.IsNullOrEmpty(classFullName)) { - System.Type result = null; - AssemblyQualifiedTypeName parsedName = TypeNameParser.Parse(classFullName); - if (!string.IsNullOrEmpty(parsedName.Assembly)) + Assembly[] ass = AppDomain.CurrentDomain.GetAssemblies(); + foreach (Assembly a in ass) { - result = TypeFromAssembly(parsedName, false); - } - else - { - if (!string.IsNullOrEmpty(classFullName)) + result = a.GetType(classFullName, false, false); + if (result != null) { - Assembly[] ass = AppDomain.CurrentDomain.GetAssemblies(); - foreach (Assembly a in ass) - { - result = a.GetType(classFullName, false, false); - if (result != null) - break; //<<<<<================ - } + break; //<<<<<================ } } - - return result; } + } + + return result; + } public static System.Type TypeFromAssembly(string type, string assembly, bool throwIfError) { @@ -646,7 +648,7 @@ private static MethodInfo SafeGetMethod(System.Type type, MethodInfo method, Sys MethodInfo foundMethod = null; try - { + { typesToSearch.Add(type); if (type.IsInterface) @@ -785,63 +787,63 @@ public static System.Type GetCollectionElementType(this IEnumerable collectionIn return GetCollectionElementType(collectionType); } - public static System.Type GetCollectionElementType(System.Type collectionType) + public static System.Type GetCollectionElementType(System.Type collectionType) + { + if (collectionType == null) + { + throw new ArgumentNullException("collectionType"); + } + if (collectionType.IsArray) + { + return collectionType.GetElementType(); + } + if (collectionType.IsGenericType) { - if (collectionType == null) + List interfaces = collectionType.GetInterfaces().Where(t => t.IsGenericType).ToList(); + if (collectionType.IsInterface) { - throw new ArgumentNullException("collectionType"); + interfaces.Add(collectionType); } - if (collectionType.IsArray) + var enumerableInterface = interfaces.FirstOrDefault(t => t.GetGenericTypeDefinition() == typeof (IEnumerable<>)); + if (enumerableInterface != null) { - return collectionType.GetElementType(); + return enumerableInterface.GetGenericArguments()[0]; } - if (collectionType.IsGenericType) - { - List interfaces = collectionType.GetInterfaces().Where(t => t.IsGenericType).ToList(); - if (collectionType.IsInterface) - { - interfaces.Add(collectionType); - } - var enumerableInterface = interfaces.FirstOrDefault(t => t.GetGenericTypeDefinition() == typeof (IEnumerable<>)); - if (enumerableInterface != null) - { - return enumerableInterface.GetGenericArguments()[0]; - } - } - return null; } + return null; + } - /// - /// Try to find a property, that can be managed by NHibernate, from a given type. - /// - /// The given . - /// The name of the property to find. - /// true if the property exists; otherwise false. - /// - /// When the user defines a field.xxxxx access strategy should be because both the property and the field exists. - /// NHibernate can work even when the property does not exist but in this case the user should use the appropriate accessor. - /// - public static bool HasProperty(this System.Type source, string propertyName) + /// + /// Try to find a property, that can be managed by NHibernate, from a given type. + /// + /// The given . + /// The name of the property to find. + /// true if the property exists; otherwise false. + /// + /// When the user defines a field.xxxxx access strategy should be because both the property and the field exists. + /// NHibernate can work even when the property does not exist but in this case the user should use the appropriate accessor. + /// + public static bool HasProperty(this System.Type source, string propertyName) + { + if (source == typeof (object) || source == null) { - if (source == typeof (object) || source == null) - { - return false; - } - if (string.IsNullOrEmpty(propertyName)) - { - return false; - } + return false; + } + if (string.IsNullOrEmpty(propertyName)) + { + return false; + } - PropertyInfo property = source.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); + PropertyInfo property = source.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); - if (property != null) - { - return true; - } - return HasProperty(source.BaseType, propertyName) || source.GetInterfaces().Any(@interface => HasProperty(@interface, propertyName)); + if (property != null) + { + return true; } + return HasProperty(source.BaseType, propertyName) || source.GetInterfaces().Any(@interface => HasProperty(@interface, propertyName)); + } - /// + /// /// Check if a method is declared in a given . /// /// The method to check. diff --git a/src/NHibernate/Util/TypeNameParser.cs b/src/NHibernate/Util/TypeNameParser.cs index 958bbf2d39a..aca2a600549 100644 --- a/src/NHibernate/Util/TypeNameParser.cs +++ b/src/NHibernate/Util/TypeNameParser.cs @@ -1,14 +1,20 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Runtime.Serialization; using System.Text; using System.Text.RegularExpressions; namespace NHibernate.Util { + [Serializable] public class ParserException : Exception { public ParserException(string message) : base(message) { } + + protected ParserException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } } public class TypeNameParser @@ -232,4 +238,4 @@ private static bool NeedDefaultAssembly(string typeFullName) return NeedDefaultNamespaceOrDefaultAssembly(typeFullName) && typeFullName.IndexOf(',') < 0; } } -} \ No newline at end of file +}