简体   繁体   中英

Get properties of the application referencing a C# class library from the library

What I'm trying to accomplish is this; I have a class library I've made, but I want to be able to detect which application is using it since I have several applications using one library, but I want to be able to make certain functions available to one application and not have them available to any other applications, all while only having a single standalone class library. The information I'd like to be able to retrieve when the class library is referenced or called upon by an application is; the application name, version, and if it is signed.

Is this possible at all?

You can use reflection System.Reflection.Assembly.GetEntryAssembly() to find the entry point for an application (eg. the executable assembly that was originally run).

Assembly caller = Assembly.GetEntryAssembly();
var name = caller.GetName();
var version = name.Version;

// etc. 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM