开发者

Using Main from a class library instead of the program

开发者 https://www.devze.com 2023-04-04 20:09 出处:网络
I have numerous projects that all contain the exact same boilerplate code inside of the main function. They all reference the same assembly (which is the one providing a majority of the functionality)

I have numerous projects that all contain the exact same boilerplate code inside of the main function. They all reference the same assembly (which is the one providing a majority of the functionality). This assembly is not referenced by anybody except for the ones who use this same boilerplate main code.

Is it possible to have a Main function inside of a class within the assembly and use it within the program referencing the assembly instead of a class within the current assembly? I would prefer to not even write a Main function within the programs if I can.

EDIT: I want the Main inside of开发者_JAVA技巧 the referenced assembly to BE the entry point.


No, you cannot skip the static Main function in your executable assemblies because that's the entry point but you could perfectly fine define a method in this assembly with the same signature that will be invoked from the Main methods of all projects that need this boilerplate code.

For example:

static void Main(string[] args)
{
    SomeClass.SomeMethodToDoBoilerplate(args);
    SomeSpecificMethods();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消