c# - Share common functionality between two static classes -


i need share common functionality between 2 static classes:

public static class class {     public static void classmethod()     {        sharedmethod<object>();     }       //ideally private method     internal static void sharedmethod<t>()     {      } }  public static class genericclass<t> {     public static void genericclassmethod()     {        sharedmethod<t>();     } } 

is there better design here? internal last choice, method sharedmethod has no significance outside 2 classes.

requirements:

  1. i can't combine them single class, need them separately, 1 generic , other not.

  2. the classes need not strictly static, shouldn't instantiable or inheritable.

  3. sharedmethod can fall in either class, doesn't matter.

this workaround doesn't meet 3 requirements (which impossible imo) made same functionality wanted.

i ended using single class marc suggested in comments. had generic class nested inside non generic class act generic functionality.

public static class class {     public static void classmethod()     {         sharedmethod<object>();     }        static void sharedmethod<t>()     {         //----     }        public static void genericclassmethod<t>()     {         return genericclass<t>.sharedmethod();     }      static class genericclass<t>      {         static void sharedmethod()         {             //available here since private members of outer class visible nested class             sharedmethod<t>();         }     } } 

so now, though calling has done little differently how wanted in question, functionally both equal.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -