DSL Boo完整实例
DSL
Model
对应的DSL内容
treatment of default_customer
upon bad_credit:
authorize_funds cart.Total, "We require full authorization of the amount in low credit rating scenarios"
define preferred_customer:
customer.TotalPurchaseAmount > 5000
define default_customer:
customer.TotalPurchaseAmount <= 5000
treatment of preferred_customer
upon bad_credit:
authorize_funds cart.Total * 0.5, "For preferred customers we only authorize half the amount"
upon cart_update:
when cart.Total > 1000:
add_cart_discount 5, "Preferred members gets 5% discount for orders over 1,000$"
DSL集成
// create the actual policies
var policies = new CustomerPolicies("Scripts");
// get a policy for this customer
AbstractCustomerPolicy policy = policies.For(preferredCustomer);
Console.WriteLine("Selected policy for {0}: {1} ",
policy.CustomerSpecification,
policy);
// somehow here we derive what our current state is...
// check if customer have treatment for the bad credit state
if (policy.HasTreatmentFor(States.BadCredit) == false)
return;
// get the treatment to apply
Treatment treatment = policy.TreatmentForState(States.BadCredit);
Console.WriteLine("Treatment for bad credit is: {0}", treatment.Description);
// execute the treatment on the shopping cart view
treatment.Execute(shoppingCart.GenerateView());
关于这个例子的详细内容可以参考 http://www.cnblogs.com/2018/category/399342.html 阅读相关的图书
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南