Skip to content

Instantly share code, notes, and snippets.

@lennybacon
Created November 19, 2014 13:03
Show Gist options
  • Save lennybacon/bd42967c913998c9b1f4 to your computer and use it in GitHub Desktop.
Save lennybacon/bd42967c913998c9b1f4 to your computer and use it in GitHub Desktop.
.NET Component Licensing
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