minor quality adjustments

This commit is contained in:
daver32
2022-07-28 20:06:45 +02:00
parent b0311c7977
commit 658526359a
2 changed files with 23 additions and 23 deletions
+3 -2
View File
@@ -23,12 +23,13 @@ namespace InterfaceGenerator
{
context.RegisterForSyntaxNotifications(() => new SyntaxReceiver());
#if DEBUG
#if DEBUG
if (!Debugger.IsAttached)
{
// sadly this is Windows only so as of now :(
Debugger.Launch();
}
#endif
#endif
}
public void Execute(GeneratorExecutionContext context)
+20 -21
View File
@@ -24,46 +24,45 @@ namespace InterfaceGenerator
}
//Ref: https://stackoverflow.com/questions/27105909/get-fully-qualified-metadata-name-in-roslyn
public static string GetFullMetadataName(this ISymbol s, bool useNameWhenNotFound = false)
public static string GetFullMetadataName(this ISymbol symbol, bool useNameWhenNotFound = false)
{
if (s == null || IsRootNamespace(s))
if (IsRootNamespace(symbol))
{
if (useNameWhenNotFound)
{
return s.Name;
}
return string.Empty;
return useNameWhenNotFound ? symbol.Name : string.Empty;
}
var sb = new StringBuilder(s.MetadataName);
var last = s;
var stringBuilder = new StringBuilder(symbol.MetadataName);
var last = symbol;
s = s.ContainingSymbol;
symbol = symbol.ContainingSymbol;
while (!IsRootNamespace(s))
while (!IsRootNamespace(symbol))
{
if (s is ITypeSymbol && last is ITypeSymbol)
if (symbol is ITypeSymbol && last is ITypeSymbol)
{
sb.Insert(0, '+');
stringBuilder.Insert(0, '+');
}
else
{
sb.Insert(0, '.');
stringBuilder.Insert(0, '.');
}
sb.Insert(0, s.OriginalDefinition.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat));
//sb.Insert(0, s.MetadataName);
s = s.ContainingSymbol;
stringBuilder.Insert(0, symbol.OriginalDefinition.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat));
symbol = symbol.ContainingSymbol;
}
var retval = sb.ToString();
return string.IsNullOrEmpty(retval) && useNameWhenNotFound ? s.Name : retval;
var retVal = stringBuilder.ToString();
if (string.IsNullOrWhiteSpace(retVal) && useNameWhenNotFound)
{
return symbol.Name;
}
return retVal;
}
private static bool IsRootNamespace(ISymbol symbol)
{
INamespaceSymbol s = null;
return ((s = symbol as INamespaceSymbol) != null) && s.IsGlobalNamespace;
return symbol is INamespaceSymbol { IsGlobalNamespace: true };
}
}
}