Skip to content

Commit

Permalink
Merge pull request godotengine#66253 from raulsntos/dotnet/assembly-m…
Browse files Browse the repository at this point in the history
…ay-be-null

C#: Guard against null assemblies
  • Loading branch information
neikeq authored Sep 22, 2022
2 parents 9f028f6 + f6d6076 commit 62792ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static bool InheritsFrom(this INamedTypeSymbol? symbol, string assemblyNa
{
while (symbol != null)
{
if (symbol.ContainingAssembly.Name == assemblyName &&
if (symbol.ContainingAssembly?.Name == assemblyName &&
symbol.ToString() == typeFullName)
{
return true;
Expand All @@ -47,7 +47,7 @@ public static bool InheritsFrom(this INamedTypeSymbol? symbol, string assemblyNa

while (symbol != null)
{
if (symbol.ContainingAssembly.Name == "GodotSharp")
if (symbol.ContainingAssembly?.Name == "GodotSharp")
return symbol;

symbol = symbol.BaseType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ INamedTypeSymbol GetTypeByMetadataNameOrThrow(string fullyQualifiedMetadataName)

if (typeKind == TypeKind.Struct)
{
if (type.ContainingAssembly.Name == "GodotSharp" &&
type.ContainingNamespace.Name == "Godot")
if (type.ContainingAssembly?.Name == "GodotSharp" &&
type.ContainingNamespace?.Name == "Godot")
{
return type switch
{
Expand Down Expand Up @@ -208,9 +208,9 @@ INamedTypeSymbol GetTypeByMetadataNameOrThrow(string fullyQualifiedMetadataName)
if (type.SimpleDerivesFrom(typeCache.GodotObjectType))
return MarshalType.GodotObjectOrDerived;

if (type.ContainingAssembly.Name == "GodotSharp")
if (type.ContainingAssembly?.Name == "GodotSharp")
{
switch (type.ContainingNamespace.Name)
switch (type.ContainingNamespace?.Name)
{
case "Godot":
return type switch
Expand All @@ -220,7 +220,7 @@ INamedTypeSymbol GetTypeByMetadataNameOrThrow(string fullyQualifiedMetadataName)
_ => null
};
case "Collections"
when type.ContainingNamespace.FullQualifiedName() == "Godot.Collections":
when type.ContainingNamespace?.FullQualifiedName() == "Godot.Collections":
return type switch
{
{ Name: "Dictionary" } =>
Expand Down

0 comments on commit 62792ee

Please sign in to comment.