c# - Looking for something like a private interface -


i have has been bugging me of late. see, find myself writing exact same private function on , on again throughout various classes of game. essentially, method builds class object; initialization method. here brief example:

public class myclass {  public myclass() {     initialize(); }  private void initialize() {     // kung fu } } 

as can see, private method called within constructor. think might have done @ least twenty+ times in current project. want easy way implement it--via visual studio/resharpers refractoring--easily.

when using visual studio, , interface, required subscribe interface methods. this; visual studio automatically helps me , subscription-based usage of interfaces.

the real problem interfaces can't have private methods. so, guess question is: next best thing facilitate private (and required) method, meanwhile acting interface? should mention inheritance out of question because of classes in no way functionally related.

what you're looking cannot done via clever use of type system.

(if inheritance not out of question, have created abstract base class protected abstract initialize() method , protected constructor calling former method.)

if you're working visual studio, suggest create ide code snippet along these lines:

class <classname> {     public <classname>     {         initialize();     }      private void initialize()     {         // kung fu     } } 

you can assign short letter combination it, e.g. cwinit, , whenever type cwinittab, snippet inserted , can override <classname> placeholder.

you can create such snippet e.g. snippet designer extension.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -