using System.Collections.Generic;
using static System.Reflection.BindingFlags;
public static void Main()
var props = typeof(MyDerivedClass).GetProperties(Public | Instance);
var longestPropNameLen = props.Select(pi => pi.Name.Length).Max();
var testCases = new Dictionary<string, Func<PropertyInfo, MyCustomAttribute>>
["No Parameter "] = pi => pi.GetCustomAttribute<MyCustomAttribute>(),
["Inherit:True "] = pi => pi.GetCustomAttribute<MyCustomAttribute>(true),
["Inherit:False"] = pi => pi.GetCustomAttribute<MyCustomAttribute>(false)
var testResults = testCases.SelectMany(testCase => props.Select(pi => {
var attr = testCase.Value(pi);
var attrText = attr == null ? "none" : attr.Value.ToString();
return $"TEST CASE: [{testCase.Key}] - PROP: [{pi.Name.PadRight(longestPropNameLen)}] - ATTR VAL: [{attrText}]";
foreach (var result in testResults)
Console.WriteLine(result);
public class MyCustomAttribute: Attribute
public bool Value { get; set; } = true;
public MyCustomAttribute(bool value = true) => Value = value;
public abstract class MyBaseClass
public abstract string PropWithAttrOnBase { get; set; }
public abstract string PropWithAttrOnDerived { get; set; }
public abstract string PropWithAttrOverridden { get; set; }
public class MyDerivedClass : MyBaseClass
public override string PropWithAttrOnBase { get; set; }
public override string PropWithAttrOnDerived { get; set; }
public override string PropWithAttrOverridden { get; set; }
public string PropOnlyOnDerived { get; set; }