test: 修复无法递归获取所有内嵌类型的问题

This commit is contained in:
Fu Diwei
2021-06-13 18:30:50 +08:00
parent 1a3aba1f5a
commit f2abcf3f71

View File

@@ -60,16 +60,22 @@ namespace SKIT.FlurlHttpClient.Wechat
{
if (type == null) throw new ArgumentNullException(nameof(type));
static Type[] GetAllNestedTypes(Type type)
static Type[] GetAllNestedTypes(Type externalType)
{
return type.GetNestedTypes()
List<Type> lstType = new List<Type>();
foreach (Type innerType in externalType.GetNestedTypes())
{
if (innerType.IsClass)
{
lstType.Add(innerType);
lstType.AddRange(GetAllNestedTypes(innerType));
}
}
return lstType
.Where(e =>
e.IsClass &&
!e.IsAbstract &&
!e.IsInterface
)
.SelectMany(e =>
GetAllNestedTypes(e)
e.IsNestedPublic
)
.ToArray();
}
@@ -109,6 +115,12 @@ namespace SKIT.FlurlHttpClient.Wechat
// noop
}
else if (propInfo.PropertyType.IsArray)
{
if (propInfo.PropertyType.FullName.Contains("[][]"))
{
// noop
}
else
{
Type elType = propInfo.PropertyType.Assembly.GetType(propInfo.PropertyType.FullName.Replace("[]", string.Empty));
object elObj = (elType == typeof(string)) ? string.Empty : Activator.CreateInstance(elType);
@@ -120,6 +132,7 @@ namespace SKIT.FlurlHttpClient.Wechat
propInfo.SetValue(obj, prop);
}
}
else if (propInfo.PropertyType == typeof(string))
{
propInfo.SetValue(obj, string.Empty);