واجهات عامة لـ ICUSTOMERRETLIST و ICUSTOMERRET - QBFC

StackOverflow https://stackoverflow.com/questions/4246358

  •  27-09-2019
  •  | 
  •  

سؤال

أي مطوري QBFC هناك؟ أنا أستخدم QBFC لسحب أنواع مختلفة من الكائنات من QuickBooks: العملاء ، والعناصر ، والفواتير ، والرموز الضريبية ، إلخ ملخص العملية.

يبدو كائن REDOSE النموذجي

IReponseList
    IResponse
         RetList
             Ret

Iresponselist و iResponse كلاهما عام بما يكفي للعمل على جميع أنواع استجابة الاستعلام. ومع ذلك ، لا يبدو أن هناك واجهة Retlist و RET عامة يمكنني استخدامها للتجريد. ليس لدي سوى واجهات محددة من النوع مثل IcustomerRetList ، و IsalestaxCoderTlist ، وما إلى ذلك. أود أن أكتب الكود بشكل مستقل عن نوع قائمة الإرجاع هو ....

هل هناك واجهة لـ Retlist أو Ret لا يمكنني العثور عليها؟

شكرًا

هل كانت مفيدة؟

المحلول

الواجهة IQBBase هو الأقرب إلى ما تبحث عنه. معظم كل شيء في QBFC مشتق من IQBase, ، بما في ذلك جميع أنواع الاستعلام وجميع أنواع الإرجاع. استخدام IQBBase المراجع و .NET Generics من الممكن إنشاء إطار عمل للتعامل مع نتائج الاستعلام.

تحديث: مثال Iterator أدناه متاح الآن كجزء من مكتبة Zombie لـ QBFC ، والتي يمكنك ذلك الاستيلاء من جيثب.

على سبيل المثال ، إليك جهاز تكرار عام يأخذ نوع 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
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top