0

我正在构建我的自定义组件。我试图通过 GetProperty("propertyname").GetValue() 读取 PipleBuffer 的值,如下所示:

    public override void ProcessInput(int inputID, PipelineBuffer buffer)
    {
        while (buffer.NextRow())
        {
            string nk = buffer[1].ToString();
            string nk1 = buffer.GetType().GetProperty("NK").GetValue(buffer, null).ToString();

在 line buffer[1].ToString() 工作正常,但在下一行它无法抛出:

NullReferenceException : 对象引用未设置为对象的实例

请提供任何线索。

无法创建 PipleBuffer 的对象实例,因为它处于保护级别。

4

1 回答 1

0

要么buffer.GetType().GetProperty("NK")为空,要么buffer.GetType().GetProperty("NK").GetValue(buffer, null)为空。

如下更改您的代码并找出:

PropertyInfo prop = buffer.GetType().GetProperty("NK");
if (prop == null)
{
    throw new Exception("prop is null!");
}

object value = prop.GetValue(buffer, null);
if (value == null)
{
    throw new Exception("value is null!");
}

string nk1 = value.ToString();

请注意,这仅用于诊断目的。我不建议您将其保留在代码中!

于 2010-07-12T03:06:25.960 回答