编译c#2.0后,枚举整数值发生变化

时间:2013-09-17 16:27:47

标签: asp.net enums

我在我的核心应用程序中有这些代码

[System.Serializable()]
public enum FieldOfDiscipline : int
{
None = 0,
ArchitecturalEngineeringFacilitiesManagement = 1,
ArtsLibraryScienceServices = 2,
AssetManagement = 3,
BusinessCorporatePlanning = 4,
DataStatistics = 5,
ExecutiveAssistance = 6,
FinancialServices = 7,
HealthServices = 8,
HumanResourceTrainingServices = 9,
InformationTechnologyServices = 10,
InternalAudit = 11,
InternationalOperations = 12,
LegalInvestigationServices = 13,
LoansCreditOperations = 14,         
ManagerialExecutive = 15,
PaymentsSettlements = 16,
ProcurementServices = 17,
PublicRelationsCommunications = 18,
ResearchDevelopment = 19,
Others = 255
}

我在我的网络服务中使用它

现在,当我引用我的Web服务并在我的Web应用程序中使用枚举时,它给了我一个不同的整数值,所以我调查了我引用的定义

#region Assembly App_WebReferences.3joumvby.dll, v2.0.50727
// C:\Users\Carlo\AppData\Local\Temp\Temporary ASP.NET Files\bsper.website\6db12346\_shadow\6f228f03\286299993\30323649\App_WebReferences.3joumvby.dll
#endregion

using System;
using System.CodeDom.Compiler;
using System.Xml.Serialization;

namespace BSPeR.ApplicationServiceProvider
{
    [Serializable]
    [XmlType(Namespace = "http://tempuri.org/")]
    [GeneratedCode("System.Xml", "4.0.30319.2022")]
    public enum FieldOfDiscipline
    {
        None = 0,
        ArchitecturalEngineeringFacilitiesManagement = 1,
        ArtsLibraryScienceServices = 2,
        AssetManagement = 3,
        BusinessCorporatePlanning = 4,
        DataStatistics = 5,
        ExecutiveAssistance = 6,
        FinancialServices = 7,
        HealthServices = 8,
        HumanResourceTrainingServices = 9,
        InformationTechnologyServices = 10,
        InternalAudit = 11,
        InternationalOperations = 12,
        LegalInvestigationServices = 13,
        LoansCreditOperations = 14,
        ManagerialExecutive = 15,
        PaymentsSettlements = 16,
        ProcurementServices = 17,
        PublicRelationsCommunications = 18,
        ResearchDevelopment = 19,
        Others = 20,
    }
}

注意到其他人的整数值?它从255改为20。

例如,当我使用此代码时

(int)FieldOfDiscipline.Others它将返回一个整数值20而不是255

如何获取原始值或我指定的值?

1 个答案:

答案 0 :(得分:1)

WSDL使用XML模式来描述数据类型。 .NET枚举(int和label)没有直接等效的XML模式数据类型,因此.NET将枚举表示为一组标签。因此,int值不会出现在Web服务的服务描述(WSDL + XSD)中。我只能假设客户端代理生成过程(我假设的svcutil)已经生成了自己的int值。

另请参阅此类似的Java问题:Enum Type in WSDL representation