Skip to content

Conversation

TimothyMakkison
Copy link
Contributor

@TimothyMakkison TimothyMakkison commented Apr 3, 2025

Incomplete source generated refit logic. Needless to say this PR is still in progress, I tried to throw it together.

Future Plans

  • Fix the todos
  • I need to do a lot of refactoring
  • Check logic
  • Add Query and MultiPart support
  • Hopefully figure out how to reference Refittypes in the source generator without it breaking
    • This is why I had to add the Configuration types
  • If my understanding of AOT is correct I can safely get the interface MethodInfo and pass it to functions.
  • Support Refit should emit diagnostics for invalid interfaces #1885
  • Rewrite half the tests to work with source generated logic :(

If we go ahead with this a couple of things may break.

image

@TimothyMakkison
Copy link
Contributor Author

TimothyMakkison commented Apr 4, 2025

Okay, after reading my notes and doing a couple of experiments:

  • We might be able to support attributes inheriting from attributes, it will be very awkward and doable, although I'm not sure it would be worth it.
    • this relies on GetCustomAttributes working In aot. The generated code will be super janky
  • Query parameters won't be able to support runtime serialisation. (See below)
    • It will be possible to create a compile time serializer, but it won't handle inheritance.
    • I could make this backwards compatible by:
      • Making users add an attribute somewhere to enable AotRefit. This would tell the generator to emit a compile time query serialiser.
      • Emit some code that tries to use runtime serialisation, if it fails we switch to a compile time version.
        • This would generate a load of
      • Determine if the project has PublishAot enabled (I don't know if this is possible)
        and emit compile time serialisation code
void Descend([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type t)
{
    foreach (var p in t.GetProperties())
    {
        Console.WriteLine(p.Name);
        Descend(p.PropertyType); //  't' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods'
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant