Note that there are some explanatory texts on larger screens.

plurals
  1. POUse a Template method in place of repeated code
    primarykey
    data
    text
    <p>I have 4 methods which have similar code</p> <pre><code>private void LogExceptions(ObjA.Input input, int customerId) { //ObjA is a big object, thats why I try not to send the whole object in this method Log(input); Log(ObjA.Exceptions); } private void LogExceptions(ObjB.Input input, int customerId) { //ObjB is a big object, thats why I try not to send the whole object in this method Log(input); Log(ObjB.Exceptions); } </code></pre> <p>and so on</p> <p>I am not able to make it a template method such as</p> <pre><code>private void LogExceptions&lt;T1,T2&gt;(T1 input, int customerId) whereas T1:ObjA.Input,ObjB.Input { Log(T1); Log(T2); } </code></pre> <p>How to do it or is there any other way ? Any help is appreciated in advance .</p> <p>I don't think my question was helping get proper answers.... Here is the exact code....</p> <pre><code> private void LogExceptions(AccARef.Response response) { StringBuilder sbErrors = null; if (response.ValMethod != null &amp;&amp; response.ValMethod.IsValid == false) { if (response.ValMethod.Errors.Count() &gt; 0) { sbErrors = new StringBuilder(); foreach (AccARef.Exception exp in response.ValMethod.Errors) { sbErrors.Append(" * " + exp.Message + exp.StackTrace + " "); Console.WriteLine(strError.ToString()) } } } } private void LogExceptions(AccBRef.Response response) { StringBuilder sbErrors = null; if (response.ValMethod != null &amp;&amp; response.ValMethod.IsValid == false) { if (response.ValMethod.Errors.Count() &gt; 0) { sbErrors = new StringBuilder(); foreach (AccBRef.Exception exp in response.ValMethod.Errors) { sbErrors.Append(" * " + exp.Message + exp.StackTrace + " "); Console.WriteLine(strError.ToString()) } } } } </code></pre> <p>Now AcctBRef and AcctARef cannot implement a common interface as they are not my objects. Or if they are no my objects, can I still decorate them to be mine ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload