Interfacce generico per ICustomerRetList e ICustomerRet - QBFC
-
27-09-2019 - |
Domanda
Le eventuali sviluppatori QBFC là fuori? Sto usando QBFC per tirare più tipi diversi di oggetti su Quickbooks: i clienti, gli articoli, le fatture, TaxCodes, ecc Il codice di query di dati davvero varia solo una volta che si ottiene con l'oggetto Ret così sto cercando di costruire alcune funzioni a astratto il processo.
Un aspetto tipico degli oggetti riposo come
IReponseList
IResponse
RetList
Ret
IResponseList e IResponse sono entrambi sufficientemente generico per lavorare su tutti i tipi di risposta alle query. Tuttavia, non sembra essere un RetList generico e Ret interfaccia che posso usare per l'estrazione. Ho solo interfacce di tipo-sepecific come ICustomerRetList, ISalesTaxCodeRetList, ecc mi piacerebbe scrivere il codice indipendentemente dal tipo di lista ritorno è ....
C'è un'interfaccia per RetList o Ret che io proprio non riesco a trovare?
Grazie
Soluzione
Il IQBBase
interfaccia è la cosa più vicina a quello che stai cercando. La maggior parte tutto in QBFC è derivato da IQBase
, compresi tutti i tipi di query e tutti i tipi di ritorno. Utilizzando i riferimenti IQBBase
e .NET farmaci generici è possibile creare un quadro a che fare con i risultati delle query.
Aggiornamento: l'esempio iteratore sotto è ora disponibile come parte della libreria Zombie per QBFC, che puoi grab da github .
Per esempio, ecco un iteratore generico che prende il tipo RetList e il tipo di Ret come parametri:
/// <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
}