2013-10-21 46 views
1

我想創建成員對誰我會運行具有多個值比較操作的列表C#腳本錯誤對象不包含定義物業

這裏是我的代碼

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

if (respCodeList.Contains(object.Property)) 

我得到錯誤if語句:

'對象' 不包含 '財產'

定義3210

發現,通過谷歌做比較,這樣一來,但不知道爲什麼這個錯誤就要到了

完整代碼:

/* 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 
       } 
      } 
     } 

    } 
} 
+0

你能詳細說明你在比較什麼?您的.Contains方法需要字符串類型。 – Jermay

+0

是的我在這裏缺少輸入,這個列表必須與來自這個變量的值進行比較:string TransResponseCode = Row.TransResponseCode; – user2385057

+0

這樣做respCodeList.Contains(Row.TransResponseCode)get的錯誤已解決..我會編譯並檢查它是否可以在功能上工作以及 – user2385057

回答

0

只投對象作爲你的類型的對象,然後嘗試。

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

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

是不是這樣做的正確方法?添加對輸入對象的引用包含:if(respCodeList.Contains(Row.TransResponseCode)) – user2385057

+0

您可以分享您的代碼的其餘部分 –

+0

我正在使用SSIS包中的C#腳本,這將使用此讀取輸入語句Row.ColumnName,所以我想檢查是否所有來自輸入的列值都在HashSet的範圍內,然後應用然後觸發條件 – user2385057

0

我認爲這是編譯錯誤。因爲'對象'保留keyword

+0

如果C#是語言與鴨打字。但事實並非如此。 –

相關問題