C#C
C#9mo ago
6 replies
TldrOlli

✅ [CodeGen] Determining Assignability of Types

Hi Guys!

Over the past days I dipped my feet a bit in code generation with the goal of writing a proxy generator that receives a "Proxy Template" (Class) from the target assembly and a "Target Class" that should be proxied.
I quickly realized that the proxy template should support at least two different methods, which the generator must use to build the proxy, namely because the difference of
Task
and
Task<T>
return types.
I.e. I need one proxy template method that roughly looks like:

[ProxyMethodTemplate]
public async Task<T> InvokeAsync<T>() {
  var result = await proxyTarget.InvokeAsync<T>();
  return result
}


and another that handles
Task
because the return statement is invalid when awaiting:

[ProxyMethodTemplte]
public async Task Invoke() {
  await proxyTarget.InvokeAsync();
  // no return
}


With this as a starting point, I already needed a way to figure out in the code generator which of the proxy template methods should be used to wrap any given function of the target class/class to proxy.

[POST CONTINUES IN NEXT MESSAGE]
Was this page helpful?