Note that there are some explanatory texts on larger screens.

plurals
  1. POString values left out of PropertyInfo.GetValue
    primarykey
    data
    text
    <p>I am not very well-versed in Reflection, but I have been working on this bit of code for a few days trying to obtain the values of class properties. I am using an API to find the values inside of cron jobs managed by the program VisualCron.</p> <p>I'll explain the structure a bit. Each cron job has several tasks inside of it which have their own settings. The settings are stored in properties inside the TaskClass class that are declared like so:</p> <pre><code>Public Property &lt;propertyname&gt; As &lt;classname&gt; </code></pre> <p>Each property is tied to its own class, so for instance there is an Execute property inside TaskClass which is declared like this:</p> <pre><code>Public Property Execute As TaskExecuteClass </code></pre> <p>Inside TaskExecuteClass are the properties that hold the values I need. With the below block of code I have been able to retrieve the property values of all types EXCEPT strings. Coincidentally, the string values are the only values I need to get.</p> <p>I know there must be something wrong with what I've written causing this because I can't find anyone with a similar issue after lots and lots of searching. Can anyone help me please?</p> <pre><code>Dim strAdd As String = "" For Each t As VisualCronAPI.Server In vcClient.Servers.GetAll() For Each f As VisualCron.JobClass In t.Jobs.GetAll For Each s As VisualCron.TaskClass In f.Tasks Dim propVal As Object Dim propInfo As PropertyInfo() = s.GetType().GetProperties() For i As Integer = 0 To propInfo.Length - 1 With propInfo(i) If s.TaskType.ToString = propInfo(i).Name.ToString Then Dim asm As Assembly = Assembly.Load("VisualCron") Dim typeName As String = String.Format("VisualCron.{0}", propInfo(i).PropertyType.Name) Dim tp As Type = asm.GetType(typeName) Dim construct As ConstructorInfo = tp.GetConstructor(Type.EmptyTypes) Dim classInst As Object = construct.Invoke(Nothing) Dim classProps As PropertyInfo() = classInst.GetType().GetProperties() For h As Integer = 0 To classProps.Length - 1 With classProps(h) If .GetIndexParameters().Length = 0 Then propVal = .GetValue(classInst, Nothing) If Not propVal Is Nothing Then strAdd = f.Name &amp; " - " &amp; s.Name &amp; " - " &amp; .Name &amp; " - " &amp; propVal.ToString End If End If If strAdd &lt;&gt; "" Then ListBox1.Items.Add(strAdd) End If End With Next End If End With Next Next s Next f Next t </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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