Field 的 GetValue 包含太多参数

问题描述 投票:0回答:1

我有一个字段,我正在尝试提取它的值。我试图使此方法通用,因为该字段可以包含 Double 或 Color 作为其值。我可以很容易地获取字段的类型,但是每当我尝试在字段上调用

GetValue
时就会收到错误消息

“公共重载函数 GetValue(Of T)() 作为 T 的参数过多”

这是我的代码

Try
  Dim field = renderMaterial?.Fields?.GetField(slotName)

  If field IsNot Nothing Then
    Dim fieldType As Type = field.GetType()
    Dim value = field.GetValue(renderMaterial)

    If fieldType = GetType(DoubleField) AndAlso DirectCast(value, DoubleField).HasValue Then
      _Attributes.Number = DirectCast(value, DoubleField).Value
    End If

    If fieldType = GetType(Color4fField) AndAlso DirectCast(value, Color4fField).HasValue Then
      _Attributes.Color = DirectCast(value, Color4fField).SystemColorValue
    End If
  End If
Catch ex As Exception
End Try
vb.net reflection
1个回答
0
投票

您必须像这样进行测试:

If TypeOf field Is DoubleField Then
© www.soinside.com 2019 - 2024. All rights reserved.