C# GetProperty-通过反射读取属性+;SSIS自定义组件

C# GetProperty-通过反射读取属性+;SSIS自定义组件,c#,ssis,custom-component,C#,Ssis,Custom Component,我正在构建自定义组件。我正试图通过以下方式读取PipleBuffer的值 GetProperty(“propertyname”).GetValue()如下所示: public override void ProcessInput(int inputID, PipelineBuffer buffer) { while (buffer.NextRow()) { string nk = buffer[1].ToString();

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

    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();
在行缓冲区[1]处,ToString()工作正常, 但在下一行它失败了:

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

有什么线索吗


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

缓冲区.GetType().GetProperty(“NK”)为空,或者
缓冲区.GetType().GetProperty(“NK”).GetValue(缓冲区,空值)
为空

按以下方式更改您的代码并找到:

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();

注意:这仅用于诊断目的。我不建议你把这个写在代码里

你到底想用这些代码实现什么?