【问题标题】:enum integer values change after compile c# 2.0编译 c# 2.0 后枚举整数值发生变化
【发布时间】:2013-09-18 00:47:13
【问题描述】:

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

[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,
    }
}

注意到Others的整数值了吗?它从 255 更改为 20。

例如当我使用此代码时

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

我怎样才能得到原始值或我分配的值?

【问题讨论】:

  • 一个只对文本名称感兴趣的网络服务,而不是整数值。

标签: asp.net enums


【解决方案1】:

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

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

【讨论】:

  • 所以我需要避免在我的代码中使用枚举的整数值,而是使用实际的枚举类型来避免错误...感谢您的输入...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-14
  • 2012-03-15
  • 1970-01-01
  • 1970-01-01
  • 2016-12-10
  • 1970-01-01
  • 2023-03-10
相关资源
最近更新 更多