Given two classes, Class1 and Class2, where Class2 is inherited from Class1, and a property Prop1, reading the DeclaringType of the PropertyInfo for Prop1 and comparing it to the full class name of Class2 will help determine whether Prop1 is inherited or not. If Prop1 is inherited, the full class name will not be the same as the the full class name of Class2.
Class2 class2 = new Class2(); Type t = class2.GetType(); PropertyInfo[] pis = t.GetProperties(); string DeclaringType = pis.DeclaringType.ToString(); for (int i = 0; i < pis.Length; i++) {
PropertyInfo pi = (PropertyInfo)pis.GetValue(i); // Walk the property list string DeclaringType = pi.DeclaringType.ToString(); if (DeclaringType != t.FullName) { // pi is referencing a property that is inherited }
}
In 2017, with the release of Delphi 10.2 Tokyo, Embarcadero introduced a specialized implementation of the Observer pattern into the System.Classes unit. While it has been in the wild for 9 years, it remains a "hidden" architecture for many, primarily because it serves as the invisible engine behind LiveBindings. Other than live bindings, you can also use the Observer pattern as a way to update component settings to the Windows registry, an .ini file, or persist it elsewhere.
System.Classes