diff --git a/Rest.Net.Example/Program.cs b/Rest.Net.Example/Program.cs index 451b7d1..b51bb5b 100644 --- a/Rest.Net.Example/Program.cs +++ b/Rest.Net.Example/Program.cs @@ -53,6 +53,11 @@ namespace MontoyaTech.Rest.Net.Example User = 1 } + public class IncludedType + { + public int Test; + } + public static RouteFileCache FileCache = new RouteFileCache(100 * 1024 * 1024); public static void Main(string[] args) @@ -103,6 +108,7 @@ namespace MontoyaTech.Rest.Net.Example [RouteGroup("Test")] [RouteResponse(typeof(string))] + [RouteInclude(typeof(IncludedType))] public static HttpListenerResponse Status(HttpListenerContext context) { return context.Response.WithStatus(HttpStatusCode.OK).WithText("Everything is operational. 👍"); diff --git a/Rest.Net/Rest.Net.csproj b/Rest.Net/Rest.Net.csproj index 7eaec27..b1e7c77 100644 --- a/Rest.Net/Rest.Net.csproj +++ b/Rest.Net/Rest.Net.csproj @@ -17,7 +17,7 @@ MontoyaTech.Rest.Net MontoyaTech.Rest.Net True - 1.4.0 + 1.4.1 Logo_Symbol_Black_Outline.png diff --git a/Rest.Net/RestClientGenerator.cs b/Rest.Net/RestClientGenerator.cs index 0974231..7c755d1 100644 --- a/Rest.Net/RestClientGenerator.cs +++ b/Rest.Net/RestClientGenerator.cs @@ -163,6 +163,20 @@ namespace MontoyaTech.Rest.Net if (!dependencies.Contains(type)) dependencies.Add(type); } + + var routeIncludes = methodInfo.GetCustomAttributes(); + + if (routeIncludes != null) + { + foreach (var include in routeIncludes) + { + var types = this.FindTypeDependencies(include.Type); + + foreach (var type in types) + if (!dependencies.Contains(type)) + dependencies.Add(type); + } + } } return dependencies.ToList(); diff --git a/Rest.Net/RouteInclude.cs b/Rest.Net/RouteInclude.cs new file mode 100644 index 0000000..2897031 --- /dev/null +++ b/Rest.Net/RouteInclude.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MontoyaTech.Rest.Net +{ + /// + /// The outline of an Attribute that includes a type when generating a client for this route. + /// + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)] + public class RouteInclude : Attribute + { + /// + /// The type to include. + /// + public Type Type = null; + + /// + /// Creates a default route include. + /// + public RouteInclude() { } + + /// + /// Creates a new route include with the type to include. + /// + /// + public RouteInclude(Type type) + { + this.Type = type; + } + } +}