覆盖枚举类型使用Web服务 [英] Override Enum Type Consuming Web Service

查看:143
本文介绍了覆盖枚举类型使用Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我消耗在C#.NET控制台应用程序的Web服务 而这项服务是用PHP写的,我没有来源。因此,在有枚举类型,他们得到他们想要的:? 。 numebrs,串...

I'm actually consuming a web service in a Console Application in C# .NET And this Service is written in PHP and I don't have the sources. So in there Enum types they have all they want : "?" "." numebrs, string ...

所以当它在我的应用程序PTED除$ P $,我有:项目,Item0 ......与XmlAttribute

And so when it's interpreted by my application, I have : Item, Item0 ... with the XmlAttribute.

我想知道的是:是否有可能有一个类,它覆盖这些枚举有点替代。等它每次更新我的W​​eb引用?不会被删除

What I want to know is : Is it possible to have a class which override these enums to have "point" replacing "." and other which is not deleted each time I update my web reference ?

感谢您的回复

推荐答案

好了我'不是pretty的肯定,如果你可以重写它在创建服务引用时生成的枚举。

Well I'am not pretty sure if you can override the enum which is generated when creating the service reference.

也许这是你的解决方案:

Maybe this is a solution for you:

当生成服务引用,所生成的cs文件是一个局部类。你可以用相同的命名空间中创建自己的另一部分类。在这一类,你可以创建一个方法或属性返回转换enumtype。当您更新服务引用此文件将不会被覆盖。

When the service reference is generated, the .cs file that is generated is a partial class. You could create yourself another partial class with the same namespace. Within that class you can create a method or property that returns the converted enumtype. This file won't be overriden when you update your service reference.

例如:

(生成的服务引用类)

public partial class ServiceReferenceComplexType
{
    public enum EnumValues
    {
        Item0,
        Item1,
        Item2
    }
}

(自创建分部类)

(Self created partial class)

public partial class ServiceReferenceComplexType
{
    public string GetCorrectEnumValue()
    {
        // Do your enum logic magic.
        EnumValues.Tostring();
    }
}

现在你可以使用ServiceReferenceComplexType.GetCorrectEnumValue()方法来检索你的价值。

You can now use the ServiceReferenceComplexType.GetCorrectEnumValue() method to retrieve your value.

这篇关于覆盖枚举类型使用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆