سؤال

لدي قطعة من XML تبدو مثل giveacodicetagpre.

كما ترى الاشتراك Productuctidentifyertype هو مجموعة وفي هذه الحالة تحتوي فقط على عنصر واحد فقط.
كيف أتجاهل العنصر الثاني الفارغ؟

لقد حاولت إضافة "تجاهل XML"، ومع ذلك، فإنه يزيل المجموعة بأكملها وأريد فقط أن يتم إزالة العنصر الثاني في المجموعة إذا لم تكن هناك بيانات. giveacodicetagpre.

أي مساعدة سيكون موضع تقدير كبير.

تحياتي zal

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

المحلول

There is not one item in your collection but two, one of which is null

just filter null items during addition, or even before return, depending on your business logic

public SubscriptionProductIdentifierType[] SubscriptionProductIdentifier {
    get {
        return this.subscriptionProductIdentifierField.Where(s=>s!=null).ToArray();
    }
...
}

Hope this helps

نصائح أخرى

XmlIgnoreAttribute will ignore the member, not just items that are null within an array. If you have no way of filtering the results or removing the null node ahead of time, then store a local variable to hold the filtered results and lazy load it.

private SubscriptionProductIdentifierType[] _subscriptionProductIdentifierField = null;
private SubscriptionProductIdentifierType[] _filteredSubscriptionProductIdentifier = null;

public SubscriptionProductIdentifierType[] SubscriptionProductIdentifier
{
    get { 
    return this._filteredSubscriptionProductIdentifier ?? (
        _filteredSubscriptionProductIdentifier = Array.FindAll(
            this._subscriptionProductIdentifierField, 
            delegate(SubscriptionProductIdentifierType t) { return t != null; } ));

}
    set
    {
        this._subscriptionProductIdentifierField = value;
        this._filteredSubscriptionProductIdentifier = null;
    }
} 
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top