Pregunta

Cualquier desarrolladores QBFC ahí fuera? Estoy usando QBFC para tirar de varios tipos diferentes de objetos fuera de Quickbooks: clientes, artículos, facturas, TaxCodes, etc. El código de consulta de datos varía en realidad sólo una vez que llegue al objeto Ret así que estoy tratando de construir algunas funciones a Resumen del proceso.

Un típico objeto reposo se parece a

IReponseList
    IResponse
         RetList
             Ret

IResponseList y IResponse son a la vez lo suficientemente genérico para trabajar en todo tipo de respuesta a consultas. Sin embargo, no parece ser un RetList genérica e interfaz de Ret que puedo usar para la abstracción. Sólo tengo interfaces del tipo sepecific como ICustomerRetList, ISalesTaxCodeRetList, etc. Me gustaría escribir el código independiente de qué tipo de lista de regreso es ....

¿Hay una interfaz para RetList o Ret que simplemente parece que no puede encontrar?

Gracias

¿Fue útil?

Solución

El IQBBase interfaz es lo más parecido a lo que estás buscando. Casi todo en QBFC se deriva de IQBase, incluyendo todos los tipos de consulta y todos los tipos de retorno. El uso de referencias IQBBase y .NET genéricos es posible crear un marco para hacer frente a los resultados de la consulta.

Actualización: el ejemplo iterador a continuación ya está disponible como parte de la biblioteca del zombi por QBFC, que puede Horquilla de github .

Por ejemplo, aquí hay un iterador genérico que toma el tipo y el tipo RetList Ret como parámetros:

/// <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
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top