使用C#中的portable.licensing向客户添加"company"



我目前正在使用以下Portable.LLicensing构建许可证(https://github.com/dnauck/Portable.Licensing)代码:

var license = Portable.Licensing.License.New();
license.WithUniqueIdentifier(guid);
license.As(Portable.Licensing.LicenseType.Standard);
license.LicensedTo(textBox_LicenseName.Text, textBox_LicenseEmail.Text);

函数LicensedTo((有一个替代定义,它需要一个额外的参数:

LicensedTo(string name, string email, Action<Customer> configureCustomer);

如何使用此附加参数将"公司名称"与"名称和电子邮件"一起包含?

使用WithAdditionalAttributes

var license = License.New()
.WithUniqueIdentifier(Guid.NewGuid())
//Look here
.WithAdditionalAttributes(new Dictionary<string, string>
{
{"CompanyName", companyName }
})
.As(LicenseType.Trial)
.ExpiresAt(DateTime.Now.AddDays(30))
.WithMaximumUtilization(numberOfUsers)
.LicensedTo(licensedTo, contactEmail)
.CreateAndSignWithPrivateKey(privateKey, passPhrase);

并从生成的许可证中检索:

var fs = new FileStream("license.lic", FileMode.Open);
var license = License.Load(fs);
var name = license.AdditionalAttributes.Get("CompanyName");
fs.Close();

最新更新