开发者

Override Enum Type Consuming Web Service

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 ...

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

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 ?

Thanks for your re开发者_高级运维ply


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:

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.

Example:

(Generated service reference class)

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();
    }
}

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜