|
-
Mar 26th, 2014, 05:13 AM
#1
"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*
-
Mar 26th, 2014, 08:05 AM
#2
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.
-
Mar 26th, 2014, 08:13 AM
#3
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:
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:
<ServiceContract()> Public Interface IQueryHandlerService ' Concrete query handler functions <WebGet(ResponseFormat:=WebMessageFormat.Json, UriTemplate:="Brokers?query={query}")> <OperationContract()> Function GetAllBrokersForClientQueryHandler(ByVal query As GetAllBrokersForClientQueryDefinition) As IEnumerable(Of DTO.Broker) 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|