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

Marking methods [Feature("FeatureName")] 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. To protect a method without associating it with a specific feature, mark the method [Feature("Execute")].

Update: 10/12/2010: – This article has been updated to reflect the fact that the [Transform] and [SLMTransform] attributes have been deprecated as of version 3.0.1910 and later versions of Code Protector. So one should now immediately replace all instances of [Transform] in one's source code with the [Feature(“Execute”)] attribute.

The following code sample shows example usage of the facility: 

using Slps.ProtectionAttributes;

public class MyCode
{
    public void WillNotBeProtectedUnlessOneChecksTheMethodInCodeProtector()
    {
    }

    [Feature( "FeatureA" )]
    public void WillBeTiedToFeatureA()
    {
    }

    [Feature( "Execute" )]
    public void WillBeProtectedButNotTiedToASpecificFeature()
    {
    }
}

Each method marked with FeatureAttribute will be automatically included in the candidates for automated protection via any of the protection approaches :

When using the FeatureAttribute 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 the FetureAttribute - not both.

Notes:

  • Version 3.0.1910 and later of Code Protector had an additional [Transform] attribute; due to a bug in its implementation this is now deprecated and one should immediately replace all instances of [Transform] with [Feature(“Execute”)].
  • Releases of Code Protector prior to 3.0.1908.1027 had a bug which may cause the protected method to throw an exception on execution if you don't have any explicitly protected methods in an assembly.
  • Code Protector versions prior to 3.0.1910 had a single attribute, SLMTransformAttribute only - this remains in the SDK for backward compatibility purposes.