1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-07 07:56:12 +00:00

Added testing checks for JsonInclude attribute for internal properties

This commit is contained in:
JKorf 2024-08-08 09:20:26 +02:00
parent 355ecb03da
commit 93e4722a81

View File

@ -151,13 +151,22 @@ namespace CryptoExchange.Net.Testing.Comparers
private static void CheckObject(string method, JProperty prop, object obj, List<string>? ignoreProperties)
{
var resultProperties = obj.GetType().GetProperties(
var publicProperties = obj.GetType().GetProperties(
System.Reflection.BindingFlags.Public
| System.Reflection.BindingFlags.NonPublic
| System.Reflection.BindingFlags.GetProperty
| System.Reflection.BindingFlags.SetProperty
| System.Reflection.BindingFlags.Instance).Select(p => (p, ((JsonPropertyNameAttribute?)p.GetCustomAttributes(typeof(JsonPropertyNameAttribute), true).SingleOrDefault())?.Name));
var internalProperties = obj.GetType().GetProperties(
System.Reflection.BindingFlags.NonPublic
| System.Reflection.BindingFlags.GetProperty
| System.Reflection.BindingFlags.SetProperty
| System.Reflection.BindingFlags.Instance)
.Where(p => p.CustomAttributes.Any(x => x.AttributeType == typeof(JsonIncludeAttribute)))
.Select(p => (p, ((JsonPropertyNameAttribute?)p.GetCustomAttributes(typeof(JsonPropertyNameAttribute), true).SingleOrDefault())?.Name));
var resultProperties = publicProperties.Concat(internalProperties);
// Property has a value
var property = resultProperties.SingleOrDefault(p => p.Name == prop.Name).p;
property ??= resultProperties.SingleOrDefault(p => p.p.Name == prop.Name).p;