It feels awkward having to do it this way as the class no longer becomes reusable/package-able into a class library without having to fiddle with the main method.
It doesn't have to be that way.
For example, each of your scripts could still have the same structure it does, but also have a private static void Main(string[] args)
method. (It could be non-private if you want - it all depends on your needs.)
That way it's standalone (can be compiled as a single input to a single output then run) which can occasionally be handy, but could also be used as part of a class library. The presence of a Main
method in no way prevents the class being used from other classes, after all.
It's not clear whether you've got one Program.cs
file or one per script. If you've got one per script, each of which is just 4-5 lines, that does seem somewhat pointless.
Now this certainly wouldn't be how I'd normally structure a large application - but if the point is to have several "scripts" each of which can be run standalone, then giving each class a Main
method doesn't seem too bad.
In fact, what I often do for demo purposes is have several classes with Main
methods in a single project, then have a separate entry point (which is in Program.cs
) which uses reflection to find all the others and then allows the user/presenter to choose which one to run.
If all your code makes sense to have in a single class, then having a tiny extra entry method doesn't seem such a problem. If it's actually a case of too much code for a single class regardless of where the entry point is, that's a different matter. (So if you stuck to having a single ScriptClass
when actually you should give different tasks to different classes, that would be bad too.) Likewise if he really is insisting on all the code being in a single method, that's definitely a problem for testing and maintainability.
I suggest you set the entry point disagreement aside for the moment: work out the cleanest way to structure everything else about the code, and then it really doesn't matter whether the Main
method goes in Program.cs
or within another class.