Would you like If / Else instructions to check for enabled features or specifically request a licensed system among your main program logic?
I don’t see how you can disable functionality without If / Else instructions, but you can keep it pretty neat if you have a license class that takes care of everything for you.
I will have a license class that initializes when the application starts and has a public bool IsFeatureLicensed(string MethodName) .
Each method that provides the function that you want to protect under license will have the following:
If (LicenceManager.IsFeatureLicensed(Reflection.MethodBase.GetCurrentMethod.Name)) { //Do your stuff! } else { //Throw exception or show error message or something. }
The IsFeatureLicensed method in the LicenseManager class that you create will look for the method name and check whether the license allows you to use the function that the method provides. It should return True in all cases except when the license prohibits the use of this function.
Thus, each method makes an identical call to the license manager (which simplifies its maintenance), and everything related to licensing is encapsulated in one class. This allows you to very easily change the licensing method (for example, you can simply return True for everything during development), and the rest of the application does not need to be touched.
source share