Modified the RestClientGenerator to prevent infinite dependency tracing. This method is a little cleaner too. Bumped package version to 1.8.8

This commit is contained in:
MattMo 2025-06-02 11:31:15 -07:00
parent f116be9908
commit d0d64ef570
2 changed files with 16 additions and 46 deletions

View File

@ -17,7 +17,7 @@
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName> <AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace> <RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
<GenerateDocumentationFile>True</GenerateDocumentationFile> <GenerateDocumentationFile>True</GenerateDocumentationFile>
<Version>1.8.7</Version> <Version>1.8.8</Version>
<PackageReleaseNotes></PackageReleaseNotes> <PackageReleaseNotes></PackageReleaseNotes>
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon> <PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile> <PackageReadmeFile>README.md</PackageReadmeFile>

View File

@ -58,79 +58,49 @@ namespace MontoyaTech.Rest.Net
/// Finds all the dependencies for a given type and returns them. /// Finds all the dependencies for a given type and returns them.
/// </summary> /// </summary>
/// <param name="type"></param> /// <param name="type"></param>
/// <param name="dependencies"></param>
/// <returns></returns> /// <returns></returns>
protected internal virtual List<Type> FindTypeDependencies(Type type) protected internal virtual HashSet<Type> FindTypeDependencies(Type type, HashSet<Type> dependencies = null)
{ {
var dependencies = new HashSet<Type>(); if (dependencies == null)
dependencies = new HashSet<Type>();
else if (dependencies.Contains(type))
return dependencies;
else if (!this.IsTypeDotNet(type))
dependencies.Add(type);
var arguments = type.GetGenericArguments(); var arguments = type.GetGenericArguments();
if (arguments != null) if (arguments != null)
{
foreach (var argument in arguments) foreach (var argument in arguments)
{
if (argument != type) if (argument != type)
{ this.FindTypeDependencies(argument, dependencies);
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)) if (this.IsTypeDotNet(type))
return dependencies.ToList(); return dependencies;
dependencies.Add(type); dependencies.Add(type);
if (type.IsEnum) if (type.IsEnum)
return dependencies.ToList(); return dependencies;
{ this.FindTypeDependencies(type.BaseType, dependencies);
var types = this.FindTypeDependencies(type.BaseType);
for (int i = 0; i < types.Count; i++)
if (!dependencies.Contains(types[i]))
dependencies.Add(types[i]);
}
var fields = type.GetFields(); var fields = type.GetFields();
if (fields != null) if (fields != null)
{
foreach (var field in fields) foreach (var field in fields)
{
if (field.IsPublic && !field.IsSpecialName && field.FieldType != type) if (field.IsPublic && !field.IsSpecialName && field.FieldType != type)
{ this.FindTypeDependencies(field.FieldType, dependencies);
var types = this.FindTypeDependencies(field.FieldType);
for (int i = 0; i < types.Count; i++)
if (!dependencies.Contains(types[i]))
dependencies.Add(types[i]);
}
}
}
var properties = type.GetProperties(); var properties = type.GetProperties();
if (properties != null) if (properties != null)
{
foreach (var property in properties) foreach (var property in properties)
{
if (!property.IsSpecialName && property.GetSetMethod() != null && property.GetGetMethod() != null && property.PropertyType != type) if (!property.IsSpecialName && property.GetSetMethod() != null && property.GetGetMethod() != null && property.PropertyType != type)
{ this.FindTypeDependencies(property.PropertyType, dependencies);
var types = this.FindTypeDependencies(property.PropertyType);
for (int i = 0; i < types.Count; i++) return dependencies;
if (!dependencies.Contains(types[i]))
dependencies.Add(types[i]);
}
}
}
return dependencies.ToList();
} }
/// <summary> /// <summary>