Say I have four classes A,B,C and D.
D has property: Name(string)
C has property: D1(type D)
B has property: C1(type C)
A has property B1(type B)
With A1 as instance of A, I can access: A1.B1.C1.D1.Name
Is there any performance issue with this?
How deep can a property residing won’t be any huge performance hit?
Or is there a limit to this hierarchy?
If all the properties in the chain are sealed (the default) and the getters are trivial, then the JITter will probably be able to inline the chain of calls. You will incur a sequence of pointer lookups, so this technically won’t be as fast as if A had a copy of Name, but the overhead is unlikely to be significant.
If any of the properties in the chain are virtual, then I believe the JITter will not be able to inline the calls, and you will incur the overhead of one or more function calls (the property gets). That is still extremely small though (again, still assuming the getters are trivial).
As always, the only way to be sure is to measure. And be conscious of what you are measuring: if the nested chain turns out to be, say, 50% slower than A having its own copy of Name, that doesn’t mean it’s a big deal, unless your program spends a large amount of its runtime on that Name get — highly unlikely! So do the right thing first — make the program readable and maintainable first — and if you measure and find it to be a bottleneck, then look at optimising it.