How to alias 2 classes in c#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WT

    How to alias 2 classes in c#

    Hello,

    Here is my pb: I have a group of classes in 2 namespaces which are exactly
    simlilar.
    Theses classes are generated by Visual Studio when inserting a Web
    Reference, having 2 versions of a web service with a total compatibility in
    data structures, I need to write a program able to deal indiferently with
    any version of the web service.
    Writing a compatibility layer is very long and need lot of unecesary
    create/delete to transfert from one object to its correspondant object and
    call the web service api without having compiler refusing.

    It could be very usefull to have something abale to say 'class1 is an alias'
    of class2 and to be able to cast directly object of class1 to class2 and
    vis-versa. All methods and properties of the class having same names and
    type.

    Any idea ?

    Thanks, CS.

  • Marc Gravell

    #2
    Re: How to alias 2 classes in c#

    Well, if you use wsdl.exe at the command-line, you can use /sharetypes
    to do this, specifying multiple urls (or other sources) to inspect.

    That do?

    Marc

    Comment

    • Steven Cheng [MSFT]

      #3
      RE: How to alias 2 classes in c#

      Hi CS,

      For ASP.NET webservice's client proxy, if you use "Add WebReference" to
      create the proxy, it will always create a new copy of the custom types(even
      if you have add multiple reference to services that use the same custom
      types).

      As Marc suggested, you can use wsdl.exe commandline utility to generate
      the proxy, this tool has "SharedType " option that will indicate the proxy
      generation to share types.

      #Web Services Description Language Tool (Wsdl.exe)


      #Framework 2.0 - WebServices Shared Types


      #Proxy Type Sharing


      So far for webservice, the type sharing support is still limited. In WCF ,
      type sharing between multiple clients or even existing class library
      asemblies are much more enhanced.

      Sincerely,

      Steven Cheng

      Microsoft MSDN Online Support Lead


      Delighting our customers is our #1 priority. We welcome your comments and
      suggestions about how we can improve the support we provide to you. Please
      feel free to let my manager know what you think of the level of service
      provided. You can send feedback directly to my manager at:
      msdnmg@microsof t.com.

      =============== =============== =============== =====
      Get notification to my posts through email? Please refer to
      Gain technical skills through documentation and training, earn certifications and connect with the community

      ications.

      Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
      where an initial response from the community or a Microsoft Support
      Engineer within 1 business day is acceptable. Please note that each follow
      up response may take approximately 2 business days as the support
      professional working with you may need further investigation to reach the
      most efficient resolution. The offering is not appropriate for situations
      that require urgent, real-time or phone-based interactions or complex
      project analysis and dump analysis issues. Issues of this nature are best
      handled working with a dedicated Microsoft Support Engineer by contacting
      Microsoft Customer Support Services (CSS) at
      http://msdn.microsoft.com/subscripti...t/default.aspx.
      =============== =============== =============== =====
      This posting is provided "AS IS" with no warranties, and confers no rights.
      --------------------
      >From: "WT" <WT@newsgroups. nospam>
      >Subject: How to alias 2 classes in c#
      >Date: Thu, 5 Jun 2008 15:29:31 +0200
      >Hello,
      >
      >Here is my pb: I have a group of classes in 2 namespaces which are exactly
      >simlilar.
      >Theses classes are generated by Visual Studio when inserting a Web
      >Reference, having 2 versions of a web service with a total compatibility
      in
      >data structures, I need to write a program able to deal indiferently with
      >any version of the web service.
      >Writing a compatibility layer is very long and need lot of unecesary
      >create/delete to transfert from one object to its correspondant object and
      >call the web service api without having compiler refusing.
      >
      >It could be very usefull to have something abale to say 'class1 is an
      alias'
      >of class2 and to be able to cast directly object of class1 to class2 and
      >vis-versa. All methods and properties of the class having same names and
      >type.
      >
      >Any idea ?
      >
      >Thanks, CS.
      >
      >

      Comment

      • WT

        #4
        Re: How to alias 2 classes in c#

        Thanks to Marc and you Steven, I will do a try.
        Something like
        using class2 = class1 would have also been usefull.

        CS


        "Steven Cheng [MSFT]" <stcheng@online .microsoft.coma écrit dans le message
        de news:4TbBLh4xIH A.4564@TK2MSFTN GHUB02.phx.gbl. ..
        Hi CS,
        >
        For ASP.NET webservice's client proxy, if you use "Add WebReference" to
        create the proxy, it will always create a new copy of the custom
        types(even
        if you have add multiple reference to services that use the same custom
        types).
        >
        As Marc suggested, you can use wsdl.exe commandline utility to generate
        the proxy, this tool has "SharedType " option that will indicate the proxy
        generation to share types.
        >
        #Web Services Description Language Tool (Wsdl.exe)

        >
        #Framework 2.0 - WebServices Shared Types

        >
        #Proxy Type Sharing

        >
        So far for webservice, the type sharing support is still limited. In WCF ,
        type sharing between multiple clients or even existing class library
        asemblies are much more enhanced.
        >
        Sincerely,
        >
        Steven Cheng
        >
        Microsoft MSDN Online Support Lead
        >
        >
        Delighting our customers is our #1 priority. We welcome your comments and
        suggestions about how we can improve the support we provide to you. Please
        feel free to let my manager know what you think of the level of service
        provided. You can send feedback directly to my manager at:
        msdnmg@microsof t.com.
        >
        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        Gain technical skills through documentation and training, earn certifications and connect with the community

        ications.
        >
        Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
        where an initial response from the community or a Microsoft Support
        Engineer within 1 business day is acceptable. Please note that each follow
        up response may take approximately 2 business days as the support
        professional working with you may need further investigation to reach the
        most efficient resolution. The offering is not appropriate for situations
        that require urgent, real-time or phone-based interactions or complex
        project analysis and dump analysis issues. Issues of this nature are best
        handled working with a dedicated Microsoft Support Engineer by contacting
        Microsoft Customer Support Services (CSS) at
        http://msdn.microsoft.com/subscripti...t/default.aspx.
        =============== =============== =============== =====
        This posting is provided "AS IS" with no warranties, and confers no
        rights.
        --------------------
        >>From: "WT" <WT@newsgroups. nospam>
        >>Subject: How to alias 2 classes in c#
        >>Date: Thu, 5 Jun 2008 15:29:31 +0200
        >
        >>Hello,
        >>
        >>Here is my pb: I have a group of classes in 2 namespaces which are exactly
        >>simlilar.
        >>Theses classes are generated by Visual Studio when inserting a Web
        >>Reference, having 2 versions of a web service with a total compatibility
        in
        >>data structures, I need to write a program able to deal indiferently with
        >>any version of the web service.
        >>Writing a compatibility layer is very long and need lot of unecesary
        >>create/delete to transfert from one object to its correspondant object and
        >>call the web service api without having compiler refusing.
        >>
        >>It could be very usefull to have something abale to say 'class1 is an
        alias'
        >>of class2 and to be able to cast directly object of class1 to class2 and
        >>vis-versa. All methods and properties of the class having same names and
        >>type.
        >>
        >>Any idea ?
        >>
        >>Thanks, CS.
        >>
        >>
        >

        Comment

        • Steven Cheng [MSFT]

          #5
          Re: How to alias 2 classes in c#

          Sure. If you encounter any other problem later, welcome to post here.

          Sincerely,

          Steven Cheng

          Microsoft MSDN Online Support Lead


          Delighting our customers is our #1 priority. We welcome your comments and
          suggestions about how we can improve the support we provide to you. Please
          feel free to let my manager know what you think of the level of service
          provided. You can send feedback directly to my manager at:
          msdnmg@microsof t.com.
          --------------------
          >From: "WT" <WT@newsgroups. nospam>
          >References: <6F9C5566-FDCD-4DF8-824B-CF743A9D00A3@mi crosoft.com>
          <4TbBLh4xIHA.45 64@TK2MSFTNGHUB 02.phx.gbl>
          >In-Reply-To: <4TbBLh4xIHA.45 64@TK2MSFTNGHUB 02.phx.gbl>
          >Subject: Re: How to alias 2 classes in c#
          >Date: Fri, 6 Jun 2008 06:51:51 +0200
          >
          >Thanks to Marc and you Steven, I will do a try.
          >Something like
          >using class2 = class1 would have also been usefull.
          >
          >CS
          >
          >

          Comment

          Working...