Override Default Constructor of Partial Class with Another Partial Class

前端 未结 12 1850
时光取名叫无心
时光取名叫无心 2020-12-28 12:59

I don\'t think this is possible, but if is then I need it :)

I have a auto-generated proxy file from the wsdl.exe command line tool by Visual Studio 2008.

Th

12条回答
  •  一向
    一向 (楼主)
    2020-12-28 13:38

    For a Web service proxy generated by Visual Studio, you cannot add your own constructor in the partial class (well you can, but it does not get called). Instead, you can use the [OnDeserialized] attribute (or [OnDeserializing]) to hook in your own code at the point where the web proxy class is instantiated.

    using System.Runtime.Serialization;
    
    partial class MyWebService
    {
         [OnDeserialized]
         public void OnDeserialized(StreamingContext context)
         {
             // your code here
         }
    }
    

提交回复
热议问题