从公开枚举中删除值

时间:2017-01-15 04:03:34

标签: c# .net enums fedex

我正在尝试从项目中的public enum中删除值。我遇到的问题是,每当我删除值时,我都会得到错误

  

XML文档(1,2909)中存在错误

这段代码阻止我删除元素是什么?

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.1586.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http:Site")]
public enum TDOTT {

    /// <remarks/>
    AD,        
    /// <remarks/>
    AP,
    /// <remarks/>
    AT,
    /// <remarks/>
    AT1,
    /// <remarks/>
    AD1,
    /// <remarks/>
    ED,
    /// <remarks/>
    EP,
    /// <remarks/>
    SP,
}

如果需要进一步的代码,请告诉我,我很乐意提供。

修改
这是删除元素时的样子(我手动删除)

public enum TDOTT {

    /// <remarks/>
    AD,        
    /// <remarks/>
    AP,
    /// <remarks/>
    AT,
    /// <remarks/>
    AT1,
    /// <remarks/>
    AD1,
    /// <remarks/>
    ED,
    /// <remarks/>
    EP,
}

这就是使用C#

调用它的方式
foreach (TDOTT ts in td.DOT)
{
    Console.WriteLine("{0}: {1}", ts.T, ts.D);                                      
}

编辑2
这是进一步的C#语法,以及产生错误的行上方的注释

    static void Main(string[] args)
    {
        List<string> tempList = new List<string> { "666288603319" };

        try
        {
            foreach (var trackingNumber in tempList)
            {
                TrackRequest request = CreateTrackRequest(trackingNumber);
                TrackService service = new TrackService();
                //The below line is hit and error is thrown
                TrackReply reply = service.track(request);
            }
        }
        catch (SoapException e)
        {
            Console.WriteLine(e.Detail.InnerText);
        }
    }
    private static TrackRequest CreateTrackRequest(string trackingNumber)
    {
        TrackRequest request = new TrackRequest();

        request.WebAuthenticationDetail = new WebAuthenticationDetail();
        request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
        request.WebAuthenticationDetail.UserCredential.Key = usercredentialKEY;
        request.WebAuthenticationDetail.UserCredential.Password = usercredentialPassword;
        request.WebAuthenticationDetail.ParentCredential = new WebAuthenticationCredential();
        request.WebAuthenticationDetail.ParentCredential.Key = parentcredentialKEY;
        request.WebAuthenticationDetail.ParentCredential.Password = parentcredentialPassword;

        request.ClientDetail = new ClientDetail();
        request.ClientDetail.AccountNumber = AccountNumber;
        request.ClientDetail.MeterNumber = MeterNumber;

        request.TransactionDetail = new TransactionDetail();
        request.TransactionDetail.CustomerTransactionId = "any value";  //This is a reference field for the customer.  Any value can be used and will be provided in the response.

        request.Version = new VersionId();

        request.SelectionDetails = new TrackSelectionDetail[1] { new TrackSelectionDetail() };
        request.SelectionDetails[0].PackageIdentifier = new TrackPackageIdentifier();
        request.SelectionDetails[0].PackageIdentifier.Value = trackingNumber;

        request.SelectionDetails[0].PackageIdentifier.Type = TrackIdentifierType.TRACKING_NUMBER_OR_DOORTAG;
        request.SelectionDetails[0].ShipDateRangeBeginSpecified = false;
        request.SelectionDetails[0].ShipDateRangeEndSpecified = false;

        request.ProcessingOptions = new TrackRequestProcessingOptionType[1] { new TrackRequestProcessingOptionType() };
        request.ProcessingOptions[0] = TrackRequestProcessingOptionType.INCLUDE_DETAILED_SCANS;

        return request;
    }

编辑3
这是TrackRequest类synatx

    public partial class TrackRequest {

    private WebAuthenticationDetail webAuthenticationDetailField;

    private ClientDetail clientDetailField;

    private TransactionDetail transactionDetailField;

    private VersionId versionField;

    private TrackSelectionDetail[] selectionDetailsField;

    private string transactionTimeOutValueInMillisecondsField;

    private TrackRequestProcessingOptionType[] processingOptionsField;

    /// <remarks/>
    public WebAuthenticationDetail WebAuthenticationDetail {
        get {
            return this.webAuthenticationDetailField;
        }
        set {
            this.webAuthenticationDetailField = value;
        }
    }

    /// <remarks/>
    public ClientDetail ClientDetail {
        get {
            return this.clientDetailField;
        }
        set {
            this.clientDetailField = value;
        }
    }

    /// <remarks/>
    public TransactionDetail TransactionDetail {
        get {
            return this.transactionDetailField;
        }
        set {
            this.transactionDetailField = value;
        }
    }

    /// <remarks/>
    public VersionId Version {
        get {
            return this.versionField;
        }
        set {
            this.versionField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("SelectionDetails")]
    public TrackSelectionDetail[] SelectionDetails {
        get {
            return this.selectionDetailsField;
        }
        set {
            this.selectionDetailsField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(DataType="nonNegativeInteger")]
    public string TransactionTimeOutValueInMilliseconds {
        get {
            return this.transactionTimeOutValueInMillisecondsField;
        }
        set {
            this.transactionTimeOutValueInMillisecondsField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("ProcessingOptions")]
    public TrackRequestProcessingOptionType[] ProcessingOptions {
        get {
            return this.processingOptionsField;
        }
        set {
            this.processingOptionsField = value;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

如果这个问题确实与FedEx开发人员API有关,那么我将假设您的public enum TDOTT实际上是(直接从FedEx API文档中提取)

    public enum TrackingDateOrTimestampType {

    /// <remarks/>
    ACTUAL_DELIVERY,        
    /// <remarks/>
    ACTUAL_PICKUP,
    /// <remarks/>
    ACTUAL_TENDER,
    /// <remarks/>
    ANTICIPATED_TENDER,
    /// <remarks/>
    APPOINTMENT_DELIVERY,
    /// <remarks/>
    ESTIMATED_DELIVERY,
    /// <remarks/>
    ESTIMATED_PICKUP,
    /// <remarks/>
    SHIP,
}

现在基于相同的假设,根据发布的代码,您要排除SP,这似乎等同于SHIP

除了上面的假设,如果你发布了你的行抛出错误之后的语法,它看起来就像下面的那样(我说的是因为我已经修改了我的以满足我的需要,但这将涉及一般的想法)

static void Main(string[] args)
{
    //Pulled this from the example you gave
    List<string> tempList = new List<string> { "666288603319" };
        foreach (var trackingNumber in tempList)
        {
            TrackRequest request = CreateTrackRequest(trackingNumber);
            TrackService service = new TrackService();
            TrackReply reply = service.track(request);

            //Now here is where my syntax is set-up that should closely mirror what the FedEx API shows straight from the .zip
            if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING)
                foreach (CompletedTrackDetail completedTrackDetail in reply.CompletedTrackDetails)
                    foreach (TrackDetail trackDetail in completedTrackDetail.TrackDetails)
                        if (trackDetail.DatesOrTimes != null)
                        {
                            foreach (TrackingDateOrTimestamp timestamp in trackDetail.DatesOrTimes)
                                //if my assumption is accurate and you want to exclude ship add this
                                if (Convert.ToString(timestamp.Type) != "SHIP")
                                    Console.WriteLine("{0}: {1}", timestamp.Type, timestamp.DateOrTimestamp); 
                        }

现在查看我添加的评论,而不是尝试修改public enum,这可能与语法中需要更改的多个位置相关联,这超出了您的编码体验,我我建议修改它,因为我只是通过&#34;过滤&#34;基于timestamp.Type

供将来参考如果您希望收到有效/有用的回复,则需要包含准确的语法。如果它是敏感信息或个人信息(例如给XXX提供跟踪号),可以改变语法,但是当FedEx API源代码可以免费下载时改变public enum是非常愚蠢的。我很少仔细阅读这些论坛,但是从最近我开始学习FedEx API后我已经准备好了 - 我以为我会对此感兴趣。

如果我的任何假设不正确,请使用FedEx API中的准确代码修改您的原始帖子,我将能够提供帮助(我相信很多其他人)。< / p>