From f2abcf3f712793b2c1528b71c688614d03fa0d6f Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Sun, 13 Jun 2021 18:30:50 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E9=80=92=E5=BD=92=E8=8E=B7=E5=8F=96=E6=89=80=E6=9C=89=E5=86=85?= =?UTF-8?q?=E5=B5=8C=E7=B1=BB=E5=9E=8B=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestReflectionUtil.cs | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/test/SKIT.FlurlHttpClient.Wechat.TestTools/TestReflectionUtil.cs b/test/SKIT.FlurlHttpClient.Wechat.TestTools/TestReflectionUtil.cs index 24d272e9..1217f4ed 100644 --- a/test/SKIT.FlurlHttpClient.Wechat.TestTools/TestReflectionUtil.cs +++ b/test/SKIT.FlurlHttpClient.Wechat.TestTools/TestReflectionUtil.cs @@ -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 lstType = new List(); + 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(); } @@ -110,15 +116,22 @@ namespace SKIT.FlurlHttpClient.Wechat } else if (propInfo.PropertyType.IsArray) { - Type elType = propInfo.PropertyType.Assembly.GetType(propInfo.PropertyType.FullName.Replace("[]", string.Empty)); - object elObj = (elType == typeof(string)) ? string.Empty : Activator.CreateInstance(elType); - elObj = Convert.ChangeType(elObj, elType); - func(elObj); + 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); + elObj = Convert.ChangeType(elObj, elType); + func(elObj); - Array prop = Array.CreateInstance(elType, 1); - prop.SetValue(elObj, 0); + Array prop = Array.CreateInstance(elType, 1); + prop.SetValue(elObj, 0); - propInfo.SetValue(obj, prop); + propInfo.SetValue(obj, prop); + } } else if (propInfo.PropertyType == typeof(string)) {