저는 Reflection에 익숙하지 않지만 클래스 속성 값을 얻기 위해 며칠 동안이 코드를 작업 해 왔습니다. API를 사용하여 VisualCron 프로그램에서 관리하는 cron 작업 내부의 값을 찾습니다.PropertyInfo.GetValue에서 문자열 값이 누락되었습니다.
구조에 대해 조금 설명하겠습니다. 각 cron 작업에는 자체 설정이있는 여러 작업이 있습니다. 예를 들어 다음과 같이 선언 TaskClass 내부의 실행 특성이 있으므로, 각 속성은 자신의 클래스에 연결되어
Public Property <propertyname> As <classname>
: 설정은과 같이 선언 된 TaskClass 클래스 내부 속성에 저장됩니다
Public Property Execute As TaskExecuteClass
Inside TaskExecuteClass는 필요한 값을 보유하고있는 속성입니다. 아래 코드 블록을 사용하면 모든 유형의 문자열을 제외하고 속성 값을 검색 할 수있었습니다. 우연히도, 문자열 값은 내가 얻을 필요가있는 유일한 값입니다.
많은 문제가있는 사람과 비슷한 문제가있는 사람을 찾을 수 없기 때문에 내가 작성한 내용에 문제가 있다는 것을 알고 있습니다. 누구든지 제발 도와 주실 래요?
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 & " - " & s.Name & " - " & .Name & " - " & propVal.ToString
End If
End If
If strAdd <> "" Then
ListBox1.Items.Add(strAdd)
End If
End With
Next
End If
End With
Next
Next s
Next f
Next t
문자열을 포함하여 작업중인 작업 클래스 중 하나의 정의를 표시 할 수 있습니까? –
@ChrisDunaway 죄송합니다. 정확히 정의가 수반하는 것은 무엇입니까? 속성 및 유형 목록 – Tim
나는 TaskClass가 어떤 것인지 궁금해하고있었습니다. 누락 된 문자열이 공개로 선언 되었습니까? 당신은 그들이 단지 들판이 아니라 재산 인 것을 확신합니까? –