2010-11-22 7 views
0

QBFC開発者はいますか? QBFCを使用してQuickbooksから複数の異なるタイプのオブジェクトを取り出す:Customers、Items、Invoices、TaxCodesなど。データクエリコードは実際にはRetオブジェクトに到達したときにのみ変化するので、いくつかの関数をビルドしようとしている。プロセスを抽象化する。ICustomerRetListとICustomerRetの汎用インターフェイス - QBFC

典型的な安息オブジェクトがIResponseListとIResponseは、両方のすべてのクエリ応答タイプで作業するのに十分な汎用的な

IReponseList 
    IResponse 
     RetList 
      Ret 

のように見えます。しかし、抽象化に使用できる一般的なRetListおよびRet Interfaceはないようです。私は、ICustomerRetList、ISalesTaxCodeRetListなどの型固有のインターフェイスしか持っていません。返されるリストのTYPEに関係なく、コードを書く必要があります。

RetListまたはRetのインターフェイスはありますか見つけられないようですか?

おかげ

答えて

0

インターフェースIQBBaseあなたが探しているものに近いものです。 QBFCのほとんどはすべてIQBaseから派生しています。すべてのクエリタイプとすべての戻り値タイプが含まれます。 IQBBase参照と.NETジェネリックを使用すると、クエリ結果を扱うフレームワークを作成することができます。

更新:以下のイテレータの例は、QBFCのゾンビライブラリの一部として利用できるようになりました。grab from githubです。

例えば、ここではパラメータとしてRetListタイプとのRet型を取る一般的なイテレータです:

/// <summary> 
/// This generic class simplifies and standardizes iteration syntax 
/// for QBFC lists. Using this class we can use the foreach keyword 
/// to iterate across all items in a list. 
/// </summary> 
/// <typeparam name="L">The type of the list, for example IBillRetList</typeparam> 
/// <typeparam name="D">The type of the item, for example IBillRet</typeparam> 
public class QBFCIterator<L, D>:IEnumerable<D> where L : class, IQBBase 
{ 

    private L m_List; 

    /// <summary> 
    /// This constructor can be used for response list items or for sub-lists that are properties 
    /// on other QBFC objects. 
    /// </summary> 
    /// <param name="lst">The sub-list</param> 
    public QBFCIterator(IQBBase lst) 
    { 
     m_List = lst as L; 

     if (m_List == null && lst != null) 
     { 
      throw new Exception("iterator type mismatch"); 
     } 
    } 

    public bool IsEmpty 
    { 
     get 
     { 
      if (m_List == null) 
      { 
       return true; 
      } 
      else 
      { 
       return Count == 0; 
      } 
     } 
    } 

    /// <summary> 
    /// An efficient alternative to the Count() function 
    /// </summary> 
    public int EntityCount 
    { 
     get { return Count; } 
    } 

    public D GetFirstItem() 
    { 
     if (IsEmpty) 
     { 
      throw new Exception("Cannot retrieve item from empty list"); 
     } 
     else 
     { 
      return GetAt(0); 
     } 
    }   

    #region Late-bound properties 
    // 
    // Since .NET requires that all methods invoked on a parameterized type 
    // must compile based solely on interface constraints, we must use late 
    // binding to access the count property and GetAt methods. This may have 
    // an impact on performance and could conceivably cause run time errors 
    // with incorrect type parameters. 
    // 
    private int Count 
    { 
     get 
     { 
      if (m_List == null) 
      { 
       return 0; 
      } 
      else 
      { 
       Type t = m_List.GetType(); 

       return (int)t.InvokeMember("Count", 
        System.Reflection.BindingFlags.GetProperty, null, m_List, null); 
      } 
     } 
    } 

    private D GetAt(int idx) 
    { 
     Type t = m_List.GetType(); 

     return (D)t.InvokeMember("GetAt", 
      System.Reflection.BindingFlags.InvokeMethod, null, m_List, new Object[] { idx }); 
    } 

    #endregion 

    #region IEnumerable<D> Members 

    public IEnumerator<D> GetEnumerator() 
    { 
     if (m_List != null) 
     { 
      for (int idx = 0; idx < Count; idx++) 
      { 
       yield return GetAt(idx); 
      } 
     } 
    } 

    #endregion 

    #region IEnumerable Members 

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 
    { 
     if (m_List != null) 
     { 
      for (int idx = 0; idx < Count; idx++) 
      { 
       yield return GetAt(idx); 
      } 
     } 
    } 

    #endregion 
} 
関連する問題