Skip to content

Commit

Permalink
Skip generation if EntryPoint is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Feb 24, 2025
1 parent 3925f4c commit 84abe5b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/BUTR.NativeAOT.Generator/InjectorGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ private static string GetCallingConvention(IMethodSymbol method)
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "__stdcall" : "__cdecl";
}

private static string GetMethodName(IMethodSymbol method)
private static string? GetMethodName(IMethodSymbol method)
{
var attr = method.GetAttributes().FirstOrDefault(x => x.AttributeClass?.MetadataName.StartsWith("UnmanagedCallersOnly", StringComparison.Ordinal) == true);
if (attr?.NamedArguments.FirstOrDefault(x => x.Key == "EntryPoint") is { Value.IsNull: false, Value.Value: string entryPoint })
if (attr?.NamedArguments.FirstOrDefault(x => x.Key == "EntryPoint") is {Value: {IsNull: false, Value: string entryPoint}})
{
return entryPoint;
}

return method.MetadataName;
return null;
}

private static string GetTypeName(ITypeSymbol type, ConstMetadata? constMetadataRaw = null)
Expand Down Expand Up @@ -177,6 +176,8 @@ public void Execute(GeneratorExecutionContext context)
var methods = receiver.Methods.Select(x => context.Compilation.GetSemanticModel(x.SyntaxTree).GetDeclaredSymbol(x)).OfType<IMethodSymbol>();
foreach (var (name, methodSymbol) in methods.Select(x => (GetMethodName(x), x)).OrderBy(x => x.Item1))
{
if (string.IsNullOrEmpty(name))
continue;
var callingConvention = GetCallingConvention(methodSymbol);
var returnType = GetReturnType(methodSymbol, null);
var parameters = string.Join(", ", methodSymbol.Parameters.Select(x => GetParameterType(methodSymbol, x)).Select(param => $"{param.Type} {param.Name}"));
Expand Down

0 comments on commit 84abe5b

Please sign in to comment.