Skip to content

Commit c93ca70

Browse files
committed
Fix C# nullable reference warnings in SolidWorks service
- Use object? for ref parameters in GetAll3 calls - Add null-forgiving operator (!) after IsNullOrEmpty checks - Fixes 10 compiler warnings
1 parent 4e9524b commit c93ca70

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

solidworks-service/BluePLM.SolidWorksService/DocumentManagerAPI.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ public bool Initialize()
156156
return false;
157157
}
158158

159-
// Log key info (masked for security)
160-
var keyPrefix = key.Length > 30 ? key.Substring(0, 30) + "..." : key;
159+
// Log key info (masked for security) - key is non-null after IsNullOrEmpty check
160+
var keyPrefix = key!.Length > 30 ? key.Substring(0, 30) + "..." : key;
161161
var keyLength = key.Length;
162162
var hasCommas = key.Contains(",");
163163
var hasColon = key.Contains(":");
@@ -797,7 +797,7 @@ private Dictionary<string, string> ReadProperties(dynamic doc, string? configura
797797
if (!string.IsNullOrEmpty(value))
798798
{
799799
Console.Error.WriteLine($"[DM] Property '{name}' = '{value}'");
800-
props[name] = value;
800+
props[name!] = value;
801801
}
802802
else
803803
{
@@ -849,7 +849,7 @@ private Dictionary<string, string> ReadProperties(dynamic doc, string? configura
849849
if (!string.IsNullOrEmpty(name))
850850
{
851851
Console.Error.WriteLine($"[DM] Property[{i}] '{name}' = '{value}'");
852-
props[name] = value ?? "";
852+
props[name!] = value ?? "";
853853
}
854854
}
855855
catch (Exception indexEx)
@@ -942,7 +942,7 @@ private Dictionary<string, string> ReadProperties(dynamic doc, string? configura
942942

943943
if (!string.IsNullOrEmpty(value))
944944
{
945-
props[name] = value;
945+
props[name!] = value;
946946
Console.Error.WriteLine($"[DM] Config property '{name}' = '{value}'");
947947
}
948948
}

solidworks-service/BluePLM.SolidWorksService/SolidWorksAPI.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ ref warnings
792792
else if (!string.IsNullOrEmpty(configuration))
793793
{
794794
// Export single configuration
795-
configsToExport = new[] { configuration };
795+
configsToExport = new[] { configuration! };
796796
}
797797
else
798798
{
@@ -814,7 +814,7 @@ ref warnings
814814
string configOutputPath;
815815
if (!string.IsNullOrEmpty(filenamePattern))
816816
{
817-
var fileName = FormatExportFilename(filenamePattern, baseName, configName, props, ".step", pdmMetadata);
817+
var fileName = FormatExportFilename(filenamePattern!, baseName, configName, props, ".step", pdmMetadata);
818818
configOutputPath = Path.Combine(outputDir, fileName);
819819
}
820820
else
@@ -1430,7 +1430,7 @@ private Dictionary<string, string> GetConfigProperties(ModelDoc2 doc, string con
14301430
var fileManager = doc.Extension.CustomPropertyManager[""];
14311431
if (fileManager != null)
14321432
{
1433-
object names = null, values = null, resolved = null, types = null, linkedProps = null;
1433+
object? names = null, values = null, resolved = null, types = null, linkedProps = null;
14341434
fileManager.GetAll3(ref names, ref types, ref values, ref resolved, ref linkedProps);
14351435

14361436
var propNames = names as string[];
@@ -1463,7 +1463,7 @@ private Dictionary<string, string> GetConfigProperties(ModelDoc2 doc, string con
14631463
var configManager = doc.Extension.CustomPropertyManager[configName];
14641464
if (configManager != null)
14651465
{
1466-
object names = null, values = null, resolved = null, types = null, linkedProps = null;
1466+
object? names = null, values = null, resolved = null, types = null, linkedProps = null;
14671467
configManager.GetAll3(ref names, ref types, ref values, ref resolved, ref linkedProps);
14681468

14691469
var propNames = names as string[];

0 commit comments

Comments
 (0)