diff --git a/Rest.Net/Rest.Net.csproj b/Rest.Net/Rest.Net.csproj index e38dc6e..f304f0c 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.8.7 + 1.8.8 Logo_Symbol_Black_Outline.png README.md diff --git a/Rest.Net/RestClientGenerator.cs b/Rest.Net/RestClientGenerator.cs index 6618522..a4614b6 100644 --- a/Rest.Net/RestClientGenerator.cs +++ b/Rest.Net/RestClientGenerator.cs @@ -58,79 +58,49 @@ namespace MontoyaTech.Rest.Net /// Finds all the dependencies for a given type and returns them. /// /// + /// /// - protected internal virtual List FindTypeDependencies(Type type) + protected internal virtual HashSet FindTypeDependencies(Type type, HashSet dependencies = null) { - var dependencies = new HashSet(); + if (dependencies == null) + dependencies = new HashSet(); + else if (dependencies.Contains(type)) + return dependencies; + else if (!this.IsTypeDotNet(type)) + dependencies.Add(type); var arguments = type.GetGenericArguments(); if (arguments != null) - { foreach (var argument in arguments) - { if (argument != type) - { - var types = this.FindTypeDependencies(argument); - - for (int i = 0; i < types.Count; i++) - if (!dependencies.Contains(types[i])) - dependencies.Add(types[i]); - } - } - } + this.FindTypeDependencies(argument, dependencies); if (this.IsTypeDotNet(type)) - return dependencies.ToList(); + return dependencies; dependencies.Add(type); if (type.IsEnum) - return dependencies.ToList(); + return dependencies; - { - var types = this.FindTypeDependencies(type.BaseType); - - for (int i = 0; i < types.Count; i++) - if (!dependencies.Contains(types[i])) - dependencies.Add(types[i]); - } + this.FindTypeDependencies(type.BaseType, dependencies); var fields = type.GetFields(); if (fields != null) - { foreach (var field in fields) - { if (field.IsPublic && !field.IsSpecialName && field.FieldType != type) - { - var types = this.FindTypeDependencies(field.FieldType); - - for (int i = 0; i < types.Count; i++) - if (!dependencies.Contains(types[i])) - dependencies.Add(types[i]); - } - } - } + this.FindTypeDependencies(field.FieldType, dependencies); var properties = type.GetProperties(); if (properties != null) - { foreach (var property in properties) - { if (!property.IsSpecialName && property.GetSetMethod() != null && property.GetGetMethod() != null && property.PropertyType != type) - { - var types = this.FindTypeDependencies(property.PropertyType); + this.FindTypeDependencies(property.PropertyType, dependencies); - for (int i = 0; i < types.Count; i++) - if (!dependencies.Contains(types[i])) - dependencies.Add(types[i]); - } - } - } - - return dependencies.ToList(); + return dependencies; } ///