How To: Declaratively mark methods to be protected or licensed in your code (KB13)

Marking methods with the [Protect] or [Feature] attributes ensures the marked methods will be automatically protected during the Code Protection phase, removing the need to use Code Protector to mark methods as protected after one has created a .SLMCfg configuration file (and allowing obfuscation to be applied most easily).

Marking methods [Protect] (use <Protect> for VB projects) ensures the marked methods will be automatically protected without licensing during the Code Protection phase.

When protecting a method one can additionally license the method i.e. indicate that the protected method will require a license before it can be executed

To license a method without associating it with a specific feature, mark the method [Feature("Execute")] or [Feature] (use <Feature("Execute")> or <Feature> for VB projects).

To license a method and associate it with a specific product feature, mark the method [Feature("FeatureName")] (use <Feature("FeatureName")> for VB projects) - where FeatureName is the feature name as displayed in the Software Potential Portal.

Note: As of version 3.0.1910 the [Transform] and [SLMTransform] attributes have been deprecated.So one should now immediately replace all instances of these in one's source code with [Protect] or [Feature] attribute as appropriate.]

The following code sample shows example usage of the attributes to mark methods for protection only or both protection and licensing : 

using Slps.ProtectionAttributes;

public class MyCode
{
    public void WillNotBeProtectedUnlessOneChecksTheMethodInCodeProtector()
    {
    }

    [Protect]               //use <Protect> for VB projects
    public void WillBeProtectedWithoutLicensing()
    {
    }

    [Feature]	//use <Feature> for VB projects
    public void WillBeLicensedButNotTiedToASpecificFeature()
    {
    }

    [Feature( "FeatureA" )]	//use <Feature("FeatureA")> for VB projects
    public void WillBeLicensedAndTiedToFeatureA()
    {
    }
}

Each method marked with either the [Protect] or [Feature] Attribute will be automatically included in the candidates for automated protection via any of the protection approaches :

When using these attributes it is still necessary to generate a Code Protector .SLMCfg configuration file but it is NOT necessary to manually select any methods for protection/licensing.

NB:  One should specify protection for a method either via the .SLMCfg file or via use of the Protect/FetureAttribute - but NEVER both.