create a method in c# which takes a class object as input parameter and uses reflection to loop through all its properties recursively and returns all boolean propertyinfo as a list in csharp
main.cs
using System;
using System.Collections.Generic;
using System.Reflection;
publicstaticclassReflectionUtils{
publicstatic List<PropertyInfo> GetAllBooleanProperties(object obj) {
List<PropertyInfo> booleanProperties = new List<PropertyInfo>();
Type objectType = obj.GetType();
PropertyInfo[] properties = objectType.GetProperties();
foreach (PropertyInfo property in properties)
{
if (property.PropertyType == typeof(bool))
{
booleanProperties.Add(property);
}
elseif (property.PropertyType.IsClass && property.GetValue(obj) != null)
{
List<PropertyInfo> childProperties = GetAllBooleanProperties(property.GetValue(obj));
booleanProperties.AddRange(childProperties);
}
}
return booleanProperties;
}
}