【问题标题】:GetProperty - Reading a property via reflection + SSIS Custom ComponentGetProperty - 通过反射 + SSIS 自定义组件读取属性
【发布时间】:2011-03-14 15:03:49
【问题描述】:

我正在构建我的自定义组件。我试图通过读取 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();

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

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

请提供任何线索。

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

【问题讨论】:

  • 你到底想用这段代码完成什么?

标签: c# ssis custom-component


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-31
    • 1970-01-01
    • 1970-01-01
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多