Build an ASP.NET JavaScript Generator: Listing 2.

Using a T4 template to create code for discounts.

 <#@ template language="VB" # >

function CalculateTaxes(taxRate, ProductID, quantity, price
 <#
  If Session("StockType")  < > "Overstock" Then
# >
  , discount
 <#
  End If
# >
) {
var extendedPrice = quantity * price *
 <#
  If Session("StockType")  < > "Overstock" Then
# >
  (1-discount)
 <#
  else
# >
.9
 <#
  End If
# >
;
'rest of CalcTaxes code
}

About the Author

Peter Vogel is a system architect and principal in PH&V Information Services. PH&V provides full-stack consulting from UX design through object modeling to database design. Peter tweets about his VSM columns with the hashtag #vogelarticles. His blog posts on user experience design can be found at http://blog.learningtree.com/tag/ui/.

comments powered by Disqus

Featured

  • See Prompts Microsoft Engineers Use for Bleeding-Edge Multimodal RAG AI Research

    Vision-centric queries show how front-line experts are prompting LLMs these days.

  • AI Explains Expressions in Update to Java on VS Code

    "The Spring Tools now show code lenses above these expressions that allow you to quickly let GitHub Copilot explain those statements for you."

  • Microsoft Eases Integration with Semantic Kernel AI SDK

    The basic idea is to provide unified API abstractions, especially for idiomatic C# code, to help platform developers and others work with any provider with standard implementations for caching, telemetry, tool calling and other common tasks.

  • Final .NET 9 Preview Ships with Go-Live License

    Visual Studio developers can now download the SDK for .NET 9 Release Candidate 2 with a go-live license, meaning devs get Microsoft support for production applications even before the framework reaches general availability next month.

Subscribe on YouTube