Skip to content

Commit

Permalink
Merge f77d87e into e037d01
Browse files Browse the repository at this point in the history
  • Loading branch information
bclothier committed Oct 17, 2021
2 parents e037d01 + f77d87e commit 8e7a7f6
Showing 1 changed file with 35 additions and 1 deletion.
Expand Up @@ -51,7 +51,13 @@ private void AddImplementedInterface(Declaration potentialClassModule)
var classModule = (ClassModuleDeclaration)potentialClassModule;
foreach (var implementedInterfaceName in classModule.SupertypeNames)
{
var expressionContext = _expressionParser.Parse(implementedInterfaceName);
if (!TrySanitizeName(implementedInterfaceName, out var sanitizedName))
{
Logger.Warn("The interface name '{0}' is insane. Therefore, it cannot be resolved reliably and will be skipped.", implementedInterfaceName);
continue;
}

var expressionContext = _expressionParser.Parse(sanitizedName);
var implementedInterface = _bindingService.ResolveType(potentialClassModule, potentialClassModule, expressionContext);
if (implementedInterface.Classification != ExpressionClassification.ResolutionFailed)
{
Expand All @@ -63,5 +69,33 @@ private void AddImplementedInterface(Declaration potentialClassModule)
}
}
}

private static bool TrySanitizeName(string implementedInterfaceName, out string sanitizedName)
{
sanitizedName = string.Empty;
foreach (var part in implementedInterfaceName.Split('.'))
{
if (!string.IsNullOrWhiteSpace(sanitizedName))
{
sanitizedName += ".";
}

if (part.StartsWith("[") && part.EndsWith("]"))
{
sanitizedName += part;
continue;
}

if (part.Contains("[") || part.Contains("]"))
{
sanitizedName = null;
break;
}

sanitizedName += "[" + part + "]";
}

return !string.IsNullOrWhiteSpace(sanitizedName);
}
}
}

0 comments on commit 8e7a7f6

Please sign in to comment.