Skip to content

Commit 025bba8

Browse files
committed
Refactor InstanceFactory.
1 parent dfc62de commit 025bba8

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

NetLeaf.Bridge/InstanceFactory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ public static uint CreateInstance(string typeNamespace)
2525

2626
try
2727
{
28-
Type type = Assemblies.FindTypeInLoadedAssemblies(typeNamespace);
28+
Type type = Assemblies.FindTypeInLoadedAssemblies(typeNamespace)!;
2929
if (type == null)
3030
{
3131
Console.WriteLine($"[CreateInstance Error] Type '{typeNamespace}' not found in loaded assemblies.");
3232
return 0;
3333
}
3434

35-
object instance = Activator.CreateInstance(type);
35+
object instance = Activator.CreateInstance(type) ?? throw new Exception("Failed to create instance.");
3636
instanceMap[id] = instance;
3737
return id;
3838
}
@@ -74,11 +74,11 @@ public static void RunInstanceMethod(uint id, string methodCall)
7474
return;
7575

7676
// Convert arguments to the correct types
77-
object[] args = ConvertArguments(method, argStrings);
77+
object[] args = ConvertArguments(method, argStrings ?? Array.Empty<string>());
7878
method.Invoke(instance, args);
7979
}
8080

81-
private static string ParseMethodName(string methodCall, out string[] args)
81+
private static string? ParseMethodName(string methodCall, out string[]? args)
8282
{
8383
int parenStart = methodCall.IndexOf('(');
8484
int parenEnd = methodCall.LastIndexOf(')');

0 commit comments

Comments
 (0)