开发者

GetProperty - Reading a property via reflection + SSIS Custom Component

开发者 https://www.devze.com 2023-01-06 15:14 出处:网络
Am in process of building my custom component.Am trying to read values 开发者_运维技巧of PipleBuffer by

Am in process of building my custom component. Am trying to read values 开发者_运维技巧of PipleBuffer by GetProperty("propertyname").GetValue() as below:

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

at line buffer[1].ToString() work fine, but at next line it fails throwing :

NullReferenceException : object reference not set to an instance of an object

Any clues please.

Cannot create object instance of PipleBuffer as is under protection level.


Either buffer.GetType().GetProperty("NK") is null, or buffer.GetType().GetProperty("NK").GetValue(buffer, null) is null.

Change your code as follows and find out:

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

Note this is for diagnostic purposes only. I don't propose you keep this in your code!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号