Results 1 to 3 of 3

Thread: "Concretising" generics - for WPF service

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    "Concretising" generics - for WPF service

    (Looking for thoughts...)

    So - when you create a WCF service with a [ServiceContract()] and [DataContract()] you can't use open generics - which I do understand why.

    However - anyone have any ideas about how I could specify a small set of types and have the generics turned into concrete implementations in the service ? (Probably looking at codegen??)

    i.e. if I have a function like Add(Of TParam)(Byval lhs As TParam, ByVal rhs As TParam) As TParam I'd like it to generate:-

    AddInteger(Byval lhs As Integer, Byval rhs As Integer) As Integer

    AddDouble(Byval lhs As Double, Byval rhs As Double) As Double

    (etc.)
    Last edited by Merrion; Mar 26th, 2014 at 12:10 PM. Reason: I meant WCF *doh*

  2. #2
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: "Concretising" generics - for WPF service

    If it's a small number of types, just write them by hand. What does the implementation of that Add method look like? Is it really okay to send any type to it? I assume from the signature that it's arithmetic addition, rather than inclusion in a collection, at which point you have to ask what does it mean to add (for example) two FileSystemWatcher instances together?

    I think the underlying problem is that you don't have a good candidate method for being generic.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: "Concretising" generics - for WPF service

    "Add" was a (badly chosen) off the top of my head example.

    The actual thing I want to "concretise" is the Query->QueryHandler link.

    vb.net Code:
    1. Public Function HandleQuery(Of TQuery As IQueryDefinition(Of TResult), TResult)(query As TQuery) As TResult

    but yes - for the moment hand coding it will be as fast as writing some fancy code gen thing...
    "vb.net Code:
    1. <ServiceContract()>
    2. Public Interface IQueryHandlerService
    3.  
    4.     ' Concrete query handler functions
    5.     <WebGet(ResponseFormat:=WebMessageFormat.Json, UriTemplate:="Brokers?query={query}")>
    6.     <OperationContract()>
    7.     Function GetAllBrokersForClientQueryHandler(ByVal query As GetAllBrokersForClientQueryDefinition) As IEnumerable(Of DTO.Broker)
    8.  
    9. End Interface
    Last edited by Merrion; Mar 26th, 2014 at 08:43 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width