How to simplify property access in nested classes without strings

62 views Asked by At

First of all please suggest a better title if necessary as I can't think of an accurate one. I was wondering if there was a way to simplify an access to a property that looks like this:

ClassA.SealedClassA.InternalClassA.ReadonlyPropertyA1;

Where SealedClassA is an inner class of ClassA and InternalClassA is an inner class of SealedClassA.

Lets say I have 1000 properties like this, all accessible in the same way from ClassA, and I want to use 200 of them, for example. I also cannot modify ClassA.

Is there any way I could code something that'd let me access those that'd be more convenient than having 200 times that "long" line of code without using strings ? The only ways I know right now are either to use the whole sequence or to use reflection and strings. The problem with strings is that if the property name changes, the reflection fails.

I'm thinking something along the lines of (this doesn't work obviously, but something with only a single call):

ClassA.ReadonlyPropertyA1();

Which would be some kind of extension method. Is that doable and if not, why ?

0

There are 0 answers