c# - Generic Func<> as parameter to base method -


I may have to lose the plot, but I hope someone can tell me in the right direction.

What am I trying to do?

I am trying to write a few basic methods that take up the funk & lt;> and so that these methods can handle all the exception handling. But allow the derived sections to specify which actions they want to execute, allow them.

So far, this is the base class.

  Public abstract class servicebase & lt; T & gt; {Secure T settings {get; Set; } Secure ServiceBase (T setting) {Settings = Settings; } Public Zero ExecAction (Action Action) {try {action (); } Hold (exception exception) {new exception (exception message); }} Public Transit Exiffx & lt; T1, T2, T3, Trashlecht & gt; (Funk & lt; T1, T2, T3, TResult & gt; Function) {try {/ * What happens here?! Catch (exception exception) {new exception throw (exception message); }}}  

I want to execute an action in the derived class in the following manner (this works):

  Delete public zero (string app) , String key) {ExecAction ((=) = & gt; Delete settings (application, key)); }  

And I want to perform a functional function in a similar way in the derivative class, but I do not think what I should put in the base class for my life.

I want to be able to call it in the following manner (if possible):

  get public object (string app, string key, end of int ) {ExecFunc () = & gt; Settings. Go (app, key, expiration)); }  

Am I being too mad or is it possible? Thanks in advance for all help. Public error removal (string app, string key) {ExecAction (= =) = & < Gt; Settings. Delete (Application, Key)); } Receive public object (string app, end of string, int) {ExecFunc ((=) Get & gt; settings.gate (app, key, end);} // // public trace execFunc & lt; TResult & gt; (Funk & lt; Trtsult & gt; func) {try {return func ()); } Hold (exception exception) {new exception (exception message); }}

By the way, your exception handling looks a bit covered: First of all, this is not considered a good practice to capture exception . Instead, consider catching more specific exceptions. Secondly, you are throwing a new exception in your hold block, which means that you are losing stacktrace etc. with the original exception. Instead of restoring the original exception, you should throw ; should be used (assuming that your hold block is doing some useful work. If you are doing all you are holding and try to by throwing it. Hold Block completely.)


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -