diff --git a/Rest.Net.Example/Program.cs b/Rest.Net.Example/Program.cs index 421dfd7..451b7d1 100644 --- a/Rest.Net.Example/Program.cs +++ b/Rest.Net.Example/Program.cs @@ -17,6 +17,17 @@ namespace MontoyaTech.Rest.Net.Example public string Id; public UserRole Role { get; set; } + + public List Permissions; + + public class Permission + { + public string Name; + + public Types Type; + + public enum Types { Read, Write } + } } public class User : BaseUser diff --git a/Rest.Net/Rest.Net.csproj b/Rest.Net/Rest.Net.csproj index 17b24a1..7eaec27 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.3.9 + 1.4.0 Logo_Symbol_Black_Outline.png diff --git a/Rest.Net/RestCSharpClientGenerator.cs b/Rest.Net/RestCSharpClientGenerator.cs index f78b174..343ecd0 100644 --- a/Rest.Net/RestCSharpClientGenerator.cs +++ b/Rest.Net/RestCSharpClientGenerator.cs @@ -160,7 +160,19 @@ namespace MontoyaTech.Rest.Net protected internal virtual void GenerateCSharpIncludedTypes(List types, CodeWriter writer) { foreach (var type in types) - this.GenerateCSharpIncludedType(type, writer); + { + bool subType = false; + + //See if this type belongs to another type in the list. + if (type.DeclaringType != null) + for (int i = 0; i < types.Count && !subType; i++) + if (type.DeclaringType == types[i]) + subType = true; + + //If not, generate the C# for this type. + if (!subType) + this.GenerateCSharpIncludedType(type, types, writer); + } } /// @@ -168,7 +180,7 @@ namespace MontoyaTech.Rest.Net /// /// /// - protected internal virtual void GenerateCSharpIncludedType(Type type, CodeWriter writer) + protected internal virtual void GenerateCSharpIncludedType(Type type, List types, CodeWriter writer) { writer.WriteBreak(); @@ -200,6 +212,11 @@ namespace MontoyaTech.Rest.Net if (!property.IsSpecialName && property.GetSetMethod() != null && property.GetGetMethod() != null) this.GenerateCSharpIncludedProperty(property, writer); + //Generate C# for any types that belong to this one. + for (int i = 0; i < types.Count; i++) + if (types[i].DeclaringType == type) + GenerateCSharpIncludedType(types[i], types, writer); + writer.Outdent().WriteLine("}"); } diff --git a/Rest.Net/RestClientGenerator.cs b/Rest.Net/RestClientGenerator.cs index 3399bf3..0974231 100644 --- a/Rest.Net/RestClientGenerator.cs +++ b/Rest.Net/RestClientGenerator.cs @@ -44,6 +44,20 @@ namespace MontoyaTech.Rest.Net { var dependencies = new HashSet(); + var arguments = type.GetGenericArguments(); + + if (arguments != null) + { + foreach (var argument in arguments) + { + var types = this.FindTypeDependencies(argument); + + for (int i = 0; i < types.Count; i++) + if (!dependencies.Contains(types[i])) + dependencies.Add(types[i]); + } + } + if (this.IsTypeDotNet(type)) return dependencies.ToList(); @@ -60,20 +74,6 @@ namespace MontoyaTech.Rest.Net dependencies.Add(types[i]); } - var arguments = type.GetGenericArguments(); - - if (arguments != null) - { - foreach (var argument in arguments) - { - var types = this.FindTypeDependencies(argument); - - for (int i = 0; i < types.Count; i++) - if (!dependencies.Contains(types[i])) - dependencies.Add(types[i]); - } - } - var fields = type.GetFields(); if (fields != null)