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:
i can't combine them single class, need them separately, 1 generic , other not.
the classes need not strictly static, shouldn't instantiable or inheritable.
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
Post a Comment