Skip to content

Commit 87c7cbe

Browse files
committed
Make use of C#7.2 readonly struct and in modifier to keep assigment by ref in methods
1 parent 15bf5ce commit 87c7cbe

File tree

7 files changed

+36
-32
lines changed

7 files changed

+36
-32
lines changed

src/NHibernate.DomainModel/NHibernate.DomainModel.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<TargetFrameworks>$(NhLibTargetFrameworks)</TargetFrameworks>
66
<IsTestProject>true</IsTestProject>
77
<NoWarn>$(NoWarn);3001;3002;3003;3005</NoWarn>
8+
<LangVersion>7.2</LangVersion>
89
</PropertyGroup>
910
<PropertyGroup Condition="'$(TargetFramework)' == 'net461'">
1011
<DefineConstants>NETFX;$(DefineConstants)</DefineConstants>

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<IsTestProject>true</IsTestProject>
77
<NoWarn>$(NoWarn);3001;3002;3003;3005</NoWarn>
88
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
9+
<LangVersion>7.2</LangVersion>
910
</PropertyGroup>
1011
<PropertyGroup Condition="'$(TargetFramework)' == 'net461'">
1112
<DefineConstants>NETFX;$(DefineConstants)</DefineConstants>

src/NHibernate.TestDatabaseSetup/NHibernate.TestDatabaseSetup.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<TargetFrameworks>$(NhAppTargetFrameworks)</TargetFrameworks>
77
<IsTestProject>true</IsTestProject>
88
<NoWarn>$(NoWarn);3001;3002;3003;3005</NoWarn>
9+
<LangVersion>7.2</LangVersion>
910
</PropertyGroup>
1011
<PropertyGroup Condition="'$(TargetFramework)' == 'net461'">
1112
<DefineConstants>NETFX;$(DefineConstants)</DefineConstants>

src/NHibernate/Engine/EntityKey.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace NHibernate.Engine
1212
/// and the identifier space (eg. tablename)
1313
/// </summary>
1414
[Serializable]
15-
public struct EntityKey : ISerializable, IEquatable<EntityKey>
15+
public readonly struct EntityKey : ISerializable, IEquatable<EntityKey>
1616
{
1717
public static EntityKey Null { get; } = new EntityKey();
1818

src/NHibernate/Engine/IPersistenceContext.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public partial interface IPersistenceContext
113113
/// <item><description>an entry of NO_ROW here is interpreted as an exception</description></item>
114114
/// </list>
115115
/// </remarks>
116-
object[] GetCachedDatabaseSnapshot(EntityKey key);
116+
object[] GetCachedDatabaseSnapshot(in EntityKey key);
117117

118118
/// <summary>
119119
/// Get the values of the natural id fields as known to the underlying
@@ -123,22 +123,22 @@ public partial interface IPersistenceContext
123123
object[] GetNaturalIdSnapshot(object id, IEntityPersister persister);
124124

125125
/// <summary> Add a canonical mapping from entity key to entity instance</summary>
126-
void AddEntity(EntityKey key, object entity);
126+
void AddEntity(in EntityKey key, object entity);
127127

128128
/// <summary>
129129
/// Get the entity instance associated with the given <tt>EntityKey</tt>
130130
/// </summary>
131-
object GetEntity(EntityKey key);
131+
object GetEntity(in EntityKey key);
132132

133133
/// <summary> Is there an entity with the given key in the persistence context</summary>
134-
bool ContainsEntity(EntityKey key);
134+
bool ContainsEntity(in EntityKey key);
135135

136136
/// <summary>
137137
/// Remove an entity from the session cache, also clear
138138
/// up other state associated with the entity, all except
139139
/// for the <tt>EntityEntry</tt>
140140
/// </summary>
141-
object RemoveEntity(EntityKey key);
141+
object RemoveEntity(in EntityKey key);
142142

143143
/// <summary> Get an entity cached by unique key</summary>
144144
object GetEntity(EntityUniqueKey euk);
@@ -216,9 +216,9 @@ EntityEntry AddEntry(object entity, Status status, object[] loadedState, object
216216
/// Attempts to check whether the given key represents an entity already loaded within the
217217
/// current session.
218218
/// </summary>
219-
/// <param name="obj">The entity reference against which to perform the uniqueness check.</param>
220219
/// <param name="key">The entity key.</param>
221-
void CheckUniqueness(EntityKey key, object obj);
220+
/// <param name="obj">The entity reference against which to perform the uniqueness check.</param>
221+
void CheckUniqueness(in EntityKey key, object obj);
222222

223223
/// <summary>
224224
/// If the existing proxy is insufficiently "narrow" (derived), instantiate a new proxy
@@ -231,14 +231,14 @@ EntityEntry AddEntry(object entity, Status status, object[] loadedState, object
231231
/// <param name="key">The internal cache key for the proxied entity. </param>
232232
/// <param name="obj">(optional) the actual proxied entity instance. </param>
233233
/// <returns> An appropriately narrowed instance. </returns>
234-
object NarrowProxy(INHibernateProxy proxy, IEntityPersister persister, EntityKey key, object obj);
234+
object NarrowProxy(INHibernateProxy proxy, IEntityPersister persister, in EntityKey key, object obj);
235235

236236
/// <summary>
237237
/// Return the existing proxy associated with the given <tt>EntityKey</tt>, or the
238238
/// third argument (the entity associated with the key) if no proxy exists. Init
239239
/// the proxy to the target implementation, if necessary.
240240
/// </summary>
241-
object ProxyFor(IEntityPersister persister, EntityKey key, object impl);
241+
object ProxyFor(IEntityPersister persister,in EntityKey key, object impl);
242242

243243
/// <summary>
244244
/// Return the existing proxy associated with the given <tt>EntityKey</tt>, or the
@@ -326,13 +326,13 @@ EntityEntry AddEntry(object entity, Status status, object[] loadedState, object
326326
CollectionEntry GetCollectionEntryOrNull(object collection);
327327

328328
/// <summary> Get an existing proxy by key</summary>
329-
object GetProxy(EntityKey key);
329+
object GetProxy(in EntityKey key);
330330

331331
/// <summary> Add a proxy to the session cache</summary>
332-
void AddProxy(EntityKey key, INHibernateProxy proxy);
332+
void AddProxy(in EntityKey key, INHibernateProxy proxy);
333333

334334
/// <summary> Remove a proxy from the session cache</summary>
335-
object RemoveProxy(EntityKey key);
335+
object RemoveProxy(in EntityKey key);
336336

337337
/// <summary> Called before cascading</summary>
338338
int IncrementCascadeLevel();
@@ -360,10 +360,10 @@ EntityEntry AddEntry(object entity, Status status, object[] loadedState, object
360360
/// <summary>
361361
/// Record the fact that the association belonging to the keyed entity is null.
362362
/// </summary>
363-
void AddNullProperty(EntityKey ownerKey, string propertyName);
363+
void AddNullProperty(in EntityKey ownerKey, string propertyName);
364364

365365
/// <summary> Is the association property belonging to the keyed entity null?</summary>
366-
bool IsPropertyNull(EntityKey ownerKey, string propertyName);
366+
bool IsPropertyNull(in EntityKey ownerKey, string propertyName);
367367

368368
/// <summary>
369369
/// Change the read-only status of an entity (or proxy).
@@ -398,7 +398,7 @@ EntityEntry AddEntry(object entity, Status status, object[] loadedState, object
398398
/// <seealso cref="IPersistenceContext.SetReadOnly(object, bool)" />
399399
bool IsReadOnly(object entityOrProxy);
400400

401-
void ReplaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, object generatedId);
401+
void ReplaceDelayedEntityIdentityInsertKeys(in EntityKey oldKey, object generatedId);
402402

403403
/// <summary>Is in a two-phase load? </summary>
404404
bool IsLoadFinished { get; }

src/NHibernate/Engine/StatefulPersistenceContext.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ public object[] GetDatabaseSnapshot(object id, IEntityPersister persister)
355355
/// <item><description>an entry of NO_ROW here is interpreted as an exception</description></item>
356356
/// </list>
357357
/// </remarks>
358-
public object[] GetCachedDatabaseSnapshot(EntityKey key)
358+
public object[] GetCachedDatabaseSnapshot(in EntityKey key)
359359
{
360360
object snapshot;
361361
if (!entitySnapshotsByKey.TryGetValue(key, out snapshot))
@@ -418,7 +418,7 @@ public object[] GetNaturalIdSnapshot(object id, IEntityPersister persister)
418418
}
419419

420420
/// <summary> Add a canonical mapping from entity key to entity instance</summary>
421-
public void AddEntity(EntityKey key, object entity)
421+
public void AddEntity(in EntityKey key, object entity)
422422
{
423423
entitiesByKey[key] = entity;
424424
BatchFetchQueue.RemoveBatchLoadableEntityKey(key);
@@ -427,15 +427,15 @@ public void AddEntity(EntityKey key, object entity)
427427
/// <summary>
428428
/// Get the entity instance associated with the given <tt>EntityKey</tt>
429429
/// </summary>
430-
public object GetEntity(EntityKey key)
430+
public object GetEntity(in EntityKey key)
431431
{
432432
object result;
433433
entitiesByKey.TryGetValue(key, out result);
434434
return result;
435435
}
436436

437437
/// <summary> Is there an entity with the given key in the persistence context</summary>
438-
public bool ContainsEntity(EntityKey key)
438+
public bool ContainsEntity(in EntityKey key)
439439
{
440440
return entitiesByKey.ContainsKey(key);
441441
}
@@ -445,7 +445,7 @@ public bool ContainsEntity(EntityKey key)
445445
/// up other state associated with the entity, all except
446446
/// for the <tt>EntityEntry</tt>
447447
/// </summary>
448-
public object RemoveEntity(EntityKey key)
448+
public object RemoveEntity(in EntityKey key)
449449
{
450450
object tempObject = entitiesByKey[key];
451451
entitiesByKey.Remove(key);
@@ -525,7 +525,7 @@ public EntityEntry AddEntity(object entity, Status status, object[] loadedState,
525525
}
526526

527527
/// <summary> Adds an entity to the internal caches.</summary>
528-
public EntityEntry AddEntity(object entity, Status status, object[] loadedState, EntityKey entityKey, object version,
528+
public EntityEntry AddEntity(object entity, Status status, object[] loadedState, in EntityKey entityKey, object version,
529529
LockMode lockMode, bool existsInDatabase, IEntityPersister persister,
530530
bool disableVersionIncrement)
531531
{
@@ -712,9 +712,9 @@ public object UnproxyAndReassociate(object maybeProxy)
712712
/// Attempts to check whether the given key represents an entity already loaded within the
713713
/// current session.
714714
/// </summary>
715-
/// <param name="obj">The entity reference against which to perform the uniqueness check.</param>
716715
/// <param name="key">The entity key.</param>
717-
public void CheckUniqueness(EntityKey key, object obj)
716+
/// <param name="obj">The entity reference against which to perform the uniqueness check.</param>
717+
public void CheckUniqueness(in EntityKey key, object obj)
718718
{
719719
object entity = GetEntity(key);
720720
if (entity == obj)
@@ -738,7 +738,7 @@ public void CheckUniqueness(EntityKey key, object obj)
738738
/// <param name="key">The internal cache key for the proxied entity. </param>
739739
/// <param name="obj">(optional) the actual proxied entity instance. </param>
740740
/// <returns> An appropriately narrowed instance. </returns>
741-
public object NarrowProxy(INHibernateProxy proxy, IEntityPersister persister, EntityKey key, object obj)
741+
public object NarrowProxy(INHibernateProxy proxy, IEntityPersister persister, in EntityKey key, object obj)
742742
{
743743
bool alreadyNarrow = persister.ConcreteProxyClass.IsInstanceOfType(proxy);
744744

@@ -782,7 +782,7 @@ public object NarrowProxy(INHibernateProxy proxy, IEntityPersister persister, En
782782
/// third argument (the entity associated with the key) if no proxy exists. Init
783783
/// the proxy to the target implementation, if necessary.
784784
/// </summary>
785-
public object ProxyFor(IEntityPersister persister, EntityKey key, object impl)
785+
public object ProxyFor(IEntityPersister persister, in EntityKey key, object impl)
786786
{
787787
if (!persister.HasProxy || key.IsNull)
788788
return impl;
@@ -1076,7 +1076,7 @@ public CollectionEntry GetCollectionEntryOrNull(object collection)
10761076
}
10771077

10781078
/// <summary> Get an existing proxy by key</summary>
1079-
public object GetProxy(EntityKey key)
1079+
public object GetProxy(in EntityKey key)
10801080
{
10811081
INHibernateProxy result;
10821082
if (proxiesByKey.TryGetValue(key, out result))
@@ -1086,13 +1086,13 @@ public object GetProxy(EntityKey key)
10861086
}
10871087

10881088
/// <summary> Add a proxy to the session cache</summary>
1089-
public void AddProxy(EntityKey key, INHibernateProxy proxy)
1089+
public void AddProxy(in EntityKey key, INHibernateProxy proxy)
10901090
{
10911091
proxiesByKey[key] = proxy;
10921092
}
10931093

10941094
/// <summary> Remove a proxy from the session cache</summary>
1095-
public object RemoveProxy(EntityKey key)
1095+
public object RemoveProxy(in EntityKey key)
10961096
{
10971097
if (batchFetchQueue != null)
10981098
{
@@ -1295,13 +1295,13 @@ private object GetIndexInParent(string property, object childEntity, IEntityPers
12951295
/// <summary>
12961296
/// Record the fact that the association belonging to the keyed entity is null.
12971297
/// </summary>
1298-
public void AddNullProperty(EntityKey ownerKey, string propertyName)
1298+
public void AddNullProperty(in EntityKey ownerKey, string propertyName)
12991299
{
13001300
nullAssociations.Add(new AssociationKey(ownerKey, propertyName));
13011301
}
13021302

13031303
/// <summary> Is the association property belonging to the keyed entity null?</summary>
1304-
public bool IsPropertyNull(EntityKey ownerKey, string propertyName)
1304+
public bool IsPropertyNull(in EntityKey ownerKey, string propertyName)
13051305
{
13061306
return nullAssociations.Contains(new AssociationKey(ownerKey, propertyName));
13071307
}
@@ -1382,7 +1382,7 @@ public bool IsReadOnly(object entityOrProxy)
13821382
return isReadOnly;
13831383
}
13841384

1385-
public void ReplaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, object generatedId)
1385+
public void ReplaceDelayedEntityIdentityInsertKeys(in EntityKey oldKey, object generatedId)
13861386
{
13871387
object tempObject = entitiesByKey[oldKey];
13881388
entitiesByKey.Remove(oldKey);

src/NHibernate/NHibernate.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<PackageDescription>NHibernate is a mature, open source object-relational mapper for the .NET framework. It is actively developed, fully featured and used in thousands of successful projects.</PackageDescription>
1414
<PackageTags>ORM; O/RM; DataBase; DAL; ObjectRelationalMapping; NHibernate; ADO.Net; Core</PackageTags>
15+
<LangVersion>7.3</LangVersion>
1516
</PropertyGroup>
1617

1718
<PropertyGroup Condition="'$(TargetFramework)' == 'net461'">

0 commit comments

Comments
 (0)