- 0
Trying to Create a Method Signature I'm Happy With
-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
Microsoft veteran wants to replace every single line of C/C++ code with Rust and AI 1 2
By Usama Jawad96,
- 35 replies
- 0 views
-
Self-replicating worm malware infects exposed Redis data store used for live streaming
By Ishtiaqe Hanif,
- 1 reply
- 5 views
-
ISRG to begin making Apache HTTP Server more secure
By zikalify,
- isrg
- internet security research group
- (and 8 more)
- 1 reply
- 435 views
-
- 13 replies
- 716 views
-
- 27 replies
- 1196 views
-
Question
sathenzar
I'm trying to create a base interface / class that I am happy with that can accept a class type, request, and response. I can't quite get it structured the way I want it to be. I essentially want to have a helper assembly that will wrap any call on a given interface and perform things like timing, exception logging, etc. I want something similar to this:
I can't seem to quite get the code to be structured this way though. The closest I can get is:
public interface IWebServiceCaller<T> where T : class { R MakeServiceCall<R, C>(Expression<Func<T, Func<C, R>>> expression); } public class WebServiceCaller<T> where T : class { public R MakeServiceCall3<R, C>(Expression<Func<T, R>> expression, C request) { var exp = expression.Compile(); ValidateRequest(request); var response = exp.Invoke(ServiceClass); return response; } }You have to pass the request object to be able to access it outside the expression it seems with this method though. I haven't used expressions that much I must admit. Is there something I'm missing here? I wish I could remove that extra C request parameter and still access the instance being passed in. If I change Expression<Func<T, R>> to Expression<Func<T, C, R>>, it gets even more awkward it seems.
Part of me is thinking I don't need the T, since my class doesn't really care about what type is being called. That could change method on the interface to just R MakeServiceCall3<R, C>, but then I still would need to pass the method to be called and an extra parameter for type C (like so: MakeServiceCall3<R, C>(serviceFuncDelegate, C request);
Maybe I'm trying to force this structure too much. I like the general idea of it, just can't get the code structured the way I would like.
Link to comment
https://www.neowin.net/forum/topic/1310054-trying-to-create-a-method-signature-im-happy-with/Share on other sites
1 answer to this question
Recommended Posts