【问题标题】:C# Script Error Object Does not Contains Definition for PropertyC# 脚本错误对象不包含属性定义
【发布时间】:2013-10-29 18:09:20
【问题描述】:

我正在尝试创建一个成员列表,我将针对这些成员运行多个值的比较操作

这是我的代码

HashSet<string> respCodeList = new HashSet<string> { "051", "052", "055", "056", "058", "059", "061", "063", "064" };    

if (respCodeList.Contains(object.Property))

if 语句出现错误:

“对象”不包含“属性”的定义

通过google找到了这种比较方式,但不知道为什么会出现这个错误

完整代码:

/* Microsoft SQL Server Integration Services Script Component
*  Write scripts using Microsoft Visual C# 2008.
*  ScriptMain is the entry point class of the script.*/

using System;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.Collections.Generic;

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]


public class ScriptMain : UserComponent
{

    public override void PreExecute()
    {
        base.PreExecute();
        /*
          Add your code here for preprocessing or remove if not needed
        */
    }

    public override void PostExecute()
    {
        base.PostExecute();
        /*
          Add your code here for postprocessing or remove if not needed
          You can set read/write variables here, for example:
          Variables.MyIntVar = 100
        */
    }

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        string TermnLn = Row.TermnLn;
        string TransTypeCode = Row.TransTypeCode;
        string ReversalReason = Row.ReversalReason;
        string TransResponseCode = Row.TransResponseCode;
        string CardIssuerLn = Row.CardIssuerLn;
        string transType = Row.TransTypeCode; 
        int origTransAmount = (int)Row.origTransAmount;
        int actualTransAmount = (int)Row.actualTransAmount;


        HashSet<string> respCodeList = new HashSet<string> { "051", "052", "055", "056", "058", "059", "061", "063", "064" };



        if (TransTypeCode == "10") // IF IT IS WITHDRAWAL
        {
            if (TermnLn== "PRO1") // CHECK FOR AXIS TERMINAL
            {
                if (ReversalReason == "00") //IT IS NOT A REVERSAL
                {
                    if (respCodeList.Contains(Row.TransResponseCode))
                    {
                        Row.CashDispensed = origTransAmount/100; //cash dispense                
                    }
                }
                else
                {
                    if (respCodeList.Contains(Row.TransResponseCode))
                    {
                        Row.CashDispensed =(actualTransAmount/100 - origTransAmount/100); //cash dispense               
                    }
                }
            }
            if (TermnLn!= "PRO1" && CardIssuerLn == "PRO1") // CHECK FOR NON AXIS TERMINAL
            {
                if (ReversalReason == "00") //IT IS NOT A REVERSAL
                {
                    if (respCodeList.Contains(Row.TransResponseCode))
                    {
                        Row.CashDispensed = origTransAmount / 100; //cash dispense non axis                 
                    }
                }
                else
                {
                    if (respCodeList.Contains(Row.TransResponseCode))
                    {
                        Row.CashDispensed = (actualTransAmount / 100 - origTransAmount / 100); //cash dispense              
                    }
                }
            }

        }



        if (ReversalReason == "00") //IT IS NOT A REVERSAL
        {
            if (respCodeList.Contains(Row.TransResponseCode))
            {
                Row.SuccessTransOrigAmt = origTransAmount / 100; //SuccessTransOrigAmt


            }
        }


        if (ReversalReason != "00" && ReversalReason != " ")
        {
            if (transType == "0420" || transType == "0412" || transType == "0430")
            {
                if (origTransAmount == actualTransAmount)
                {
                    Row.ReversalAmount = origTransAmount / 100; //ReversalAmount
                }
                else
                {
                    Row.ReversalAmount = (actualTransAmount / 100 - origTransAmount / 100);  //ReversalAmount
                }
            }
        }

    }
}

【问题讨论】:

  • 您能否详细说明您要比较的内容?您的 .Contains 方法需要字符串类型。
  • 是的,我错过了这里的输入,这个列表必须与来自这个变量的值进行比较:string TransResponseCode = Row.TransResponseCode;
  • 做这个 respCodeList.Contains(Row.TransResponseCode) 得到的错误解决了..我会编译并检查它是否能正常工作

标签: c# visual-studio-2010 contains


【解决方案1】:

只需将 object 转换为您的对象类型,然后尝试。

HashSet<string> respCodeList = new HashSet<string> { "051", "052", "055", "056", "058", "059", "061", "063", "064" };    

if (respCodeList.Contains((object as YourType).Property))

【讨论】:

  • 这不是正确的做法吗?在 contains 中添加对输入对象的引用:if (respCodeList.Contains(Row.TransResponseCode))
  • 我在 SSIS 包中使用 C# 脚本,这将使用此语句 Row.ColumnName 读取输入,所以我想检查来自输入的所有列值是否在 HashSet 范围内然后应用触发条件
  • 我在原题中修改并添加了完整代码
【解决方案2】:

我认为这是编译错误。因为'object'保留了keyword

【讨论】:

  • 如果 C# 是带有鸭子类型的语言,那将是正确的。但事实并非如此。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-20
  • 2022-08-23
相关资源
最近更新 更多