Hi all,

I have a library which talks to a device over a serial port. This
library has a number of methods that can be called, in the form...

AaaResponse PerformAaa(AaaRequest request)
BbbResponse PerformBbb(BbbRequest request)
Etc.

I need to implement a short delay between calls to the device as it
needs some 'catch-up' time but I don't want to have to code this before
every call. So, ideally I'd like a generic 'Execute' type method where
the delay can be implemented before the call is made to the device. 

I could probably could use a generic delegate something like below but
it seems overly complicated/messy...

    class Operations
    {       
        public U Execute<T, U>(Func<T, U> function, T request)
        {
            // Implement delay here
            return function(request);
        }  

        public AaaResponse PerformAaa(AaaRequest request) 
        {
            Execute<AaaRequest, AaaResponse> Library.PerformAaa(request)

        }

        etc
    }

Any suggestions on how I could neaten this up?

Thanks,
John

Reply via email to