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)?

radim
  • 11
  • 1
  • 2
    `public A propertyA;` That would be a public field, not a property. – Fildor Aug 31 '17 at 12:38
  • Does https://stackoverflow.com/questions/53844/how-can-i-evaluate-a-c-sharp-expression-dynamically help? – mjwills Aug 31 '17 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. – Fildor Aug 31 '17 at 12:42

0 Answers0