|
1 | 1 | using System.Net.Http; |
| 2 | +#if NET10_0_OR_GREATER |
| 3 | +using System.Diagnostics.CodeAnalysis; |
| 4 | +#endif |
2 | 5 |
|
3 | 6 | namespace Refit |
4 | 7 | { |
5 | | - /// <summary> |
6 | | - /// IRequestBuilder. |
7 | | - /// </summary> |
8 | 8 | public interface IRequestBuilder |
9 | 9 | { |
10 | | - /// <summary> |
11 | | - /// Builds the rest result function for method. |
12 | | - /// </summary> |
13 | | - /// <param name="methodName">Name of the method.</param> |
14 | | - /// <param name="parameterTypes">The parameter types.</param> |
15 | | - /// <param name="genericArgumentTypes">The generic argument types.</param> |
16 | | - /// <returns></returns> |
17 | 10 | Func<HttpClient, object[], object?> BuildRestResultFuncForMethod( |
18 | 11 | string methodName, |
19 | 12 | Type[]? parameterTypes = null, |
20 | 13 | Type[]? genericArgumentTypes = null |
21 | 14 | ); |
22 | 15 | } |
23 | 16 |
|
24 | | - /// <summary> |
25 | | - /// |
26 | | - /// </summary> |
27 | | - /// <typeparam name="T"></typeparam> |
28 | 17 | public interface IRequestBuilder<T> : IRequestBuilder { } |
29 | 18 |
|
30 | | - /// <summary> |
31 | | - /// RequestBuilder. |
32 | | - /// </summary> |
33 | 19 | public static class RequestBuilder |
34 | 20 | { |
35 | 21 | static readonly RequestBuilderFactory PlatformRequestBuilderFactory = new(); |
36 | 22 |
|
37 | | - /// <summary> |
38 | | - /// Fors the type. |
39 | | - /// </summary> |
40 | | - /// <typeparam name="T"></typeparam> |
41 | | - /// <param name="settings">The settings.</param> |
42 | | - /// <returns></returns> |
| 23 | +#if NET10_0_OR_GREATER |
| 24 | + public static IRequestBuilder<T> ForType< [ |
| 25 | + DynamicallyAccessedMembers( |
| 26 | + DynamicallyAccessedMemberTypes.None | |
| 27 | + DynamicallyAccessedMemberTypes.PublicMethods | |
| 28 | + DynamicallyAccessedMemberTypes.NonPublicMethods |
| 29 | + )] T >(RefitSettings? settings) => |
| 30 | + PlatformRequestBuilderFactory.Create<T>(settings); |
| 31 | +#else |
43 | 32 | public static IRequestBuilder<T> ForType<T>(RefitSettings? settings) => |
44 | 33 | PlatformRequestBuilderFactory.Create<T>(settings); |
| 34 | +#endif |
45 | 35 |
|
46 | | - /// <summary> |
47 | | - /// Fors the type. |
48 | | - /// </summary> |
49 | | - /// <typeparam name="T"></typeparam> |
50 | | - /// <returns></returns> |
| 36 | +#if NET10_0_OR_GREATER |
| 37 | + public static IRequestBuilder<T> ForType< [ |
| 38 | + DynamicallyAccessedMembers( |
| 39 | + DynamicallyAccessedMemberTypes.None | |
| 40 | + DynamicallyAccessedMemberTypes.PublicMethods | |
| 41 | + DynamicallyAccessedMemberTypes.NonPublicMethods |
| 42 | + )] T >() => |
| 43 | + PlatformRequestBuilderFactory.Create<T>(null); |
| 44 | +#else |
51 | 45 | public static IRequestBuilder<T> ForType<T>() => |
52 | 46 | PlatformRequestBuilderFactory.Create<T>(null); |
| 47 | +#endif |
53 | 48 |
|
54 | | - /// <summary> |
55 | | - /// Fors the type. |
56 | | - /// </summary> |
57 | | - /// <param name="refitInterfaceType">Type of the refit interface.</param> |
58 | | - /// <param name="settings">The settings.</param> |
59 | | - /// <returns></returns> |
60 | | - public static IRequestBuilder ForType(Type refitInterfaceType, RefitSettings? settings) => |
61 | | - PlatformRequestBuilderFactory.Create(refitInterfaceType, settings); |
| 49 | +#if NET10_0_OR_GREATER |
| 50 | + [RequiresUnreferencedCode("Refit uses reflection to analyze interface methods. Ensure referenced interfaces and DTOs are preserved when trimming.")] |
| 51 | + public static IRequestBuilder ForType( |
| 52 | + [DynamicallyAccessedMembers( |
| 53 | + DynamicallyAccessedMemberTypes.None | |
| 54 | + DynamicallyAccessedMemberTypes.PublicMethods | |
| 55 | + DynamicallyAccessedMemberTypes.NonPublicMethods |
| 56 | + )] Type refitInterfaceType, |
| 57 | + RefitSettings? settings |
| 58 | + ) |
| 59 | +#else |
| 60 | + public static IRequestBuilder ForType( |
| 61 | + Type refitInterfaceType, |
| 62 | + RefitSettings? settings |
| 63 | + ) |
| 64 | +#endif |
| 65 | + { |
| 66 | + return new CachedRequestBuilderImplementation( |
| 67 | + new RequestBuilderImplementation(refitInterfaceType, settings) |
| 68 | + ); |
| 69 | + } |
62 | 70 |
|
63 | | - /// <summary> |
64 | | - /// Fors the type. |
65 | | - /// </summary> |
66 | | - /// <param name="refitInterfaceType">Type of the refit interface.</param> |
67 | | - /// <returns></returns> |
| 71 | +#if NET10_0_OR_GREATER |
| 72 | + [RequiresUnreferencedCode("Refit uses reflection to analyze interface methods. Ensure referenced interfaces and DTOs are preserved when trimming.")] |
| 73 | +#endif |
68 | 74 | public static IRequestBuilder ForType(Type refitInterfaceType) => |
69 | | - PlatformRequestBuilderFactory.Create(refitInterfaceType, null); |
| 75 | + ForType(refitInterfaceType, null); |
70 | 76 | } |
71 | 77 | } |
0 commit comments