Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>MyProp1.MyProp2 is not a property of your base object, MyProp1 is a property of that then MyProp2 is a property of the object returned by MyProp1.</p> <p>Try this : </p> <pre><code>Dim propertyInfo1 As PropertyInfo = MYITEM.GetType().GetProperty("MyProp1") Dim propertyValue1 As Object = propertyInfo.GetValue(MYITEM, Nothing) Dim propertyInfo2 As PropertyInfo = propertyValue1.GetType().GetProperty("MyProp2") Dim propertyValue2 As Object = propertyInfo2.GetValue(propertyValue1, Nothing) </code></pre> <p>You could try something like this extension method (sorry its in c#)</p> <pre><code>public static TRet GetPropertyValue&lt;TRet&gt;(this object obj, string propertyPathName) { if (obj == null) { throw new ArgumentNullException("obj"); } string[] parts = propertyPathName.Split('.'); string path = propertyPathName; object root = obj; if (parts.Length &gt; 1) { path = parts[parts.Length - 1]; parts = parts.TakeWhile((p, i) =&gt; i &lt; parts.Length-1).ToArray(); string path2 = String.Join(".", parts); root = obj.GetPropertyValue&lt;object&gt;(path2); } var sourceType = root.GetType(); return (TRet)sourceType.GetProperty(path).GetValue(root, null); } </code></pre> <p>Then to test</p> <pre><code>public class Test1 { public Test1() { this.Prop1 = new Test2(); } public Test2 Prop1 { get; set; } } public class Test2 { public Test2() { this.Prop2 = new Test3(); } public Test3 Prop2 { get; set; } } public class Test3 { public Test3() { this.Prop3 = DateTime.Now.AddDays(-1); // Yesterday } public DateTime Prop3 { get; set; } } </code></pre> <p>Usage</p> <pre><code>Test1 obj = new Test1(); var yesterday = obj.GetPropertyValue&lt;DateTime&gt;("Prop1.Prop2.Prop3"); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload