Created
November 19, 2014 13:03
-
-
Save lennybacon/bd42967c913998c9b1f4 to your computer and use it in GitHub Desktop.
.NET Component Licensing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MyNamespace | |
{ | |
[LicenseProvider(typeof(MyLicenseProvider))] | |
public class MyLicensedComponent : Component | |
{ | |
} | |
public class MyLicenseProvider : LicenseProvider | |
{ | |
public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) | |
{ | |
var licenseKey = context.GetSavedLicenseKey(type, null); | |
return licenseKey != null ? new MyLicense(licenseKey) : null; | |
} | |
} | |
public class MyLicense : License{ | |
private readonly string _licenseKey; | |
public MyLicense(string licenseKey) | |
{ | |
_licenseKey = licenseKey; | |
} | |
public override void Dispose() | |
{ | |
} | |
public override string LicenseKey { | |
get { return _licenseKey; } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment