Search Results

Search found 2 results on 1 pages for 'antirysm'.

Page 1/1 | 1 

  • Using a general class for execution with try/catch/finally?

    - by antirysm
    I find myself having a lot of this in different methods in my code: try { runABunchOfMethods(); } catch (Exception ex) { logger.Log(ex); } What about creating this: public static class Executor { private static ILogger logger; public delegate void ExecuteThis(); static Executor() { // logger = ...GetLoggerFromIoC(); } public static void Execute(ExecuteThis executeThis) { try { executeThis(); } catch (Exception ex) { logger.Log(ex); } } } And just using it like this: private void RunSomething() { Method1(someClassVar); Method2(someOtherClassVar); } ... Executor.Execute(RunSomething); Are there any downsides to this approach? (You could add Executor-methods and delegates when you want a finally and use generics for the type of Exeception you want to catch...)

    Read the article

  • Using nested classes for constants?

    - by antirysm
    What's wrong with using nested classes to group constants? Like so: public static class Constants { public static class CategoryA { public const string ValueX = "CatA_X"; public const string ValueY = "CatA_Y"; } public static class CategoryB { public const string ValueX = "CatB_X"; public const string ValueY = "CatB_Y"; } } Used like so: Console.WriteLine(Constants.CategoryA.ValueY); Console.WriteLine(Constants.CategoryB.ValueX); You could also make the "Constants"-class partial...

    Read the article

1