0

Suppose there are these classes:

class A    
{    
    public string someField="something";        
    public void MethodA(){}     
}

class B
{
    public A propertyA;
}

class C
{
    public B propertyB;
    string s1 = "propertyB.propertyA.MethodA()";        
    string s2 = "propertyB.propertyA.someField";
    public void Method()
    {
        //so for s1 it does
        propertyB.propertyA.MethodA();
        //and for s2 it does
        var something = propertyB.propertyA.someField;
        //or
        propertyB.propertyA.someField = "somethingNew"
    }
}

How can I execute a method in class A from class C represented as string s1 and get or assign value to someField(s2)?

3
  • 2
    public A propertyA; That would be a public field, not a property. Commented Aug 31, 2017 at 12:38
  • Does stackoverflow.com/questions/53844/… help? Commented Aug 31, 2017 at 12:40
  • 2
    Apart from the question if that's possible or not, I'd like to discourage doing this in the first place. What are you trying to achieve? I am sure, there will be a proper Design-Pattern for you. Commented Aug 31, 2017 at 12:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.