Skip to content

Commit

Permalink
Bit of a cleanup. Removed an unused type.
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyju committed Mar 12, 2023
1 parent d5615bb commit 36421be
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static IHostBuilder ConfigureGeneratedFunctionExecutor(this IHostBuilder

private static string GetTypesDictionary(IEnumerable<ExecutableFunction> functions)
{
var classNames = functions.Where(f => !f.IsStatic).Select(f => f.ParentFunctionClass.Name).Distinct();
var classNames = functions.Where(f => !f.IsStatic).Select(f => f.ParentFunctionClassName).Distinct();
if (!classNames.Any())
{
return
Expand Down Expand Up @@ -123,8 +123,8 @@ private static string GetMethodBody(IEnumerable<ExecutableFunction> functions)
{
sb.Append($$"""

var instanceType = types["{{function.ParentFunctionClass.Name}}"];
var c = _functionActivator.CreateInstance(instanceType, context) as {{function.ParentFunctionClass.Name}};
var instanceType = types["{{function.ParentFunctionClassName}}"];
var i = _functionActivator.CreateInstance(instanceType, context) as {{function.ParentFunctionClassName}};
""");
}

Expand All @@ -141,9 +141,9 @@ private static string GetMethodBody(IEnumerable<ExecutableFunction> functions)
}

sb.Append(function.IsStatic
? @$"{function.ParentFunctionClass.Name}.{function.MethodName}({methodParamsStr});
? @$"{function.ParentFunctionClassName}.{function.MethodName}({methodParamsStr});
}}"
: $@"c.{function.MethodName}({methodParamsStr});
: $@"i.{function.MethodName}({methodParamsStr});
}}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Azure.Functions.Worker.Sdk.Generators
internal class ExecutableFunction
{
/// <summary>
/// True if the function returns Task or void.
/// False if the function returns Task or void.
/// </summary>
internal bool IsReturnValueAssignable { set; get; }

Expand All @@ -33,7 +33,11 @@ internal class ExecutableFunction
/// </summary>
internal string EntryPoint { get; set; } = null!;

internal FunctionClass ParentFunctionClass { set; get; } = null!;
/// <summary>
/// Fully qualified type name of the parent class.
/// Ex: MyNamespace.MyClass
/// </summary>
internal string ParentFunctionClassName { get; set; } = null!;

/// <summary>
/// A collection of fully qualified type names of the parameters of the function.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ internal Parser(GeneratorExecutionContext context)

internal ICollection<ExecutableFunction> GetFunctions(List<MethodDeclarationSyntax> methods)
{
var classDict = new Dictionary<string, FunctionClass>();
var functionList = new List<ExecutableFunction>();

foreach (MethodDeclarationSyntax method in methods)
Expand Down Expand Up @@ -54,11 +53,6 @@ internal ICollection<ExecutableFunction> GetFunctions(List<MethodDeclarationSynt

var methodSymbol = model.GetDeclaredSymbol(method)!;
var fullyQualifiedClassName = methodSymbol.ContainingSymbol.ToDisplayString();
if (!classDict.TryGetValue(fullyQualifiedClassName, out var classInfo))
{
classInfo = new FunctionClass(fullyQualifiedClassName);
classDict[fullyQualifiedClassName] = classInfo;
}

var function = new ExecutableFunction
{
Expand All @@ -68,7 +62,7 @@ internal ICollection<ExecutableFunction> GetFunctions(List<MethodDeclarationSynt
ShouldAwait = IsTaskType(methodSymbol.ReturnType),
IsReturnValueAssignable = IsReturnValueAssignable(methodSymbol),
IsStatic = method.Modifiers.Any(SyntaxKind.StaticKeyword),
ParentFunctionClass = classInfo
ParentFunctionClassName = fullyQualifiedClassName
};

functionList.Add(function);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public async ValueTask ExecuteAsync(FunctionContext context)
if (string.Equals(context.FunctionDefinition.EntryPoint, ""MyCompany.MyHttpTriggers.Foo"", StringComparison.OrdinalIgnoreCase))
{{
var instanceType = types[""MyCompany.MyHttpTriggers""];
var c = _functionActivator.CreateInstance(instanceType, context) as MyCompany.MyHttpTriggers;
context.GetInvocationResult().Value = c.Foo((Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0], (Microsoft.Azure.Functions.Worker.FunctionContext)inputArguments[1]);
var i = _functionActivator.CreateInstance(instanceType, context) as MyCompany.MyHttpTriggers;
context.GetInvocationResult().Value = i.Foo((Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0], (Microsoft.Azure.Functions.Worker.FunctionContext)inputArguments[1]);
}}
if (string.Equals(context.FunctionDefinition.EntryPoint, ""MyCompany.Foo.MyAsyncStaticMethod"", StringComparison.OrdinalIgnoreCase))
{{
Expand Down Expand Up @@ -191,14 +191,14 @@ public async ValueTask ExecuteAsync(FunctionContext context)
if (string.Equals(context.FunctionDefinition.EntryPoint, ""MyCompany.MyHttpTriggers.Run1"", StringComparison.OrdinalIgnoreCase))
{{
var instanceType = types[""MyCompany.MyHttpTriggers""];
var c = _functionActivator.CreateInstance(instanceType, context) as MyCompany.MyHttpTriggers;
context.GetInvocationResult().Value = c.Run1((Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0]);
var i = _functionActivator.CreateInstance(instanceType, context) as MyCompany.MyHttpTriggers;
context.GetInvocationResult().Value = i.Run1((Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0]);
}}
if (string.Equals(context.FunctionDefinition.EntryPoint, ""MyCompany.MyHttpTriggers.Run2"", StringComparison.OrdinalIgnoreCase))
{{
var instanceType = types[""MyCompany.MyHttpTriggers""];
var c = _functionActivator.CreateInstance(instanceType, context) as MyCompany.MyHttpTriggers;
context.GetInvocationResult().Value = c.Run2((Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0], (Microsoft.Azure.Functions.Worker.FunctionContext)inputArguments[1]);
var i = _functionActivator.CreateInstance(instanceType, context) as MyCompany.MyHttpTriggers;
context.GetInvocationResult().Value = i.Run2((Microsoft.Azure.Functions.Worker.Http.HttpRequestData)inputArguments[0], (Microsoft.Azure.Functions.Worker.FunctionContext)inputArguments[1]);
}}
}}
}}
Expand Down

0 comments on commit 36421be

Please sign in to comment.