Added support for sub types in the C# client code generator. Bumped package version to 1.4.0
This commit is contained in:
parent
fafdb48d51
commit
e8735d8764
@ -17,6 +17,17 @@ namespace MontoyaTech.Rest.Net.Example
|
||||
public string Id;
|
||||
|
||||
public UserRole Role { get; set; }
|
||||
|
||||
public List<Permission> Permissions;
|
||||
|
||||
public class Permission
|
||||
{
|
||||
public string Name;
|
||||
|
||||
public Types Type;
|
||||
|
||||
public enum Types { Read, Write }
|
||||
}
|
||||
}
|
||||
|
||||
public class User : BaseUser
|
||||
|
@ -17,7 +17,7 @@
|
||||
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
|
||||
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<Version>1.3.9</Version>
|
||||
<Version>1.4.0</Version>
|
||||
<PackageReleaseNotes></PackageReleaseNotes>
|
||||
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
|
||||
</PropertyGroup>
|
||||
|
@ -160,7 +160,19 @@ namespace MontoyaTech.Rest.Net
|
||||
protected internal virtual void GenerateCSharpIncludedTypes(List<Type> 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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -168,7 +180,7 @@ namespace MontoyaTech.Rest.Net
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="writer"></param>
|
||||
protected internal virtual void GenerateCSharpIncludedType(Type type, CodeWriter writer)
|
||||
protected internal virtual void GenerateCSharpIncludedType(Type type, List<Type> 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("}");
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,20 @@ namespace MontoyaTech.Rest.Net
|
||||
{
|
||||
var dependencies = new HashSet<Type>();
|
||||
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user