Skip to content

Commit d783453

Browse files
authored
Nullability of TryGet function (#217)
1 parent 236cdb4 commit d783453

File tree

7 files changed

+19
-9
lines changed

7 files changed

+19
-9
lines changed

Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Operations/Send/ArcGISRootObjectBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public async Task<RootObjectBuilderResult> Build(
9898
// don't use cache for group layers
9999
if (
100100
mapMember is not GroupLayer
101-
&& _sendConversionCache.TryGetValue(sendInfo.ProjectId, applicationId, out ObjectReference value)
101+
&& _sendConversionCache.TryGetValue(sendInfo.ProjectId, applicationId, out ObjectReference? value)
102102
)
103103
{
104104
converted = value;

Connectors/Autocad/Speckle.Connectors.AutocadShared/Operations/Send/AutocadRootObjectBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public Task<RootObjectBuilderResult> Build(
108108
{
109109
converted = instanceProxy;
110110
}
111-
else if (_sendConversionCache.TryGetValue(sendInfo.ProjectId, applicationId, out ObjectReference value))
111+
else if (_sendConversionCache.TryGetValue(sendInfo.ProjectId, applicationId, out ObjectReference? value))
112112
{
113113
converted = value;
114114
cacheHitCount++;

Connectors/Revit/Speckle.Connectors.RevitShared/Operations/Send/RevitRootObjectBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public Task<RootObjectBuilderResult> Build(
9999
try
100100
{
101101
Base converted;
102-
if (_sendConversionCache.TryGetValue(sendInfo.ProjectId, applicationId, out ObjectReference value))
102+
if (_sendConversionCache.TryGetValue(sendInfo.ProjectId, applicationId, out ObjectReference? value))
103103
{
104104
converted = value;
105105
cacheHitCount++;

Connectors/Rhino/Speckle.Connectors.RhinoShared/Operations/Send/RhinoRootObjectBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ SendInfo sendInfo
146146
{
147147
converted = instanceProxies[applicationId];
148148
}
149-
else if (_sendConversionCache.TryGetValue(sendInfo.ProjectId, applicationId, out ObjectReference value))
149+
else if (_sendConversionCache.TryGetValue(sendInfo.ProjectId, applicationId, out ObjectReference? value))
150150
{
151151
converted = value;
152152
}

Sdk/Speckle.Connectors.Utils/Caching/ISendConversionCache.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using Speckle.Sdk.Models;
23

34
namespace Speckle.Connectors.Utils.Caching;
@@ -20,5 +21,5 @@ public interface ISendConversionCache
2021
/// <param name="objectIds"></param>
2122
public void EvictObjects(IEnumerable<string> objectIds);
2223
public void ClearCache();
23-
bool TryGetValue(string projectId, string applicationId, out ObjectReference objectReference);
24+
bool TryGetValue(string projectId, string applicationId, [NotNullWhen(true)] out ObjectReference? objectReference);
2425
}

Sdk/Speckle.Connectors.Utils/Caching/NullSendConversionCache.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using Speckle.Sdk.Models;
23

34
namespace Speckle.Connectors.Utils.Caching;
@@ -13,9 +14,13 @@ public void EvictObjects(IEnumerable<string> objectIds) { }
1314

1415
public void ClearCache() { }
1516

16-
public bool TryGetValue(string projectId, string applicationId, out ObjectReference objectReference)
17+
public bool TryGetValue(
18+
string projectId,
19+
string applicationId,
20+
[NotNullWhen(true)] out ObjectReference? objectReference
21+
)
1722
{
18-
objectReference = new ObjectReference();
23+
objectReference = null;
1924
return false;
2025
}
2126
}

Sdk/Speckle.Connectors.Utils/Caching/SendConversionCache.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using Speckle.Sdk.Models;
23

34
namespace Speckle.Connectors.Utils.Caching;
@@ -25,6 +26,9 @@ public void EvictObjects(IEnumerable<string> objectIds) =>
2526

2627
public void ClearCache() => Cache.Clear();
2728

28-
public bool TryGetValue(string projectId, string applicationId, out ObjectReference objectReference) =>
29-
Cache.TryGetValue((applicationId, projectId), out objectReference);
29+
public bool TryGetValue(
30+
string projectId,
31+
string applicationId,
32+
[NotNullWhen(true)] out ObjectReference? objectReference
33+
) => Cache.TryGetValue((applicationId, projectId), out objectReference);
3034
}

0 commit comments

Comments
 (0)