Using HOF Pattern for Transactions in Revit API
When reading the book “Functional Programming in C#”, I saw the concept of HOF. I felt that this method could be used to organize an extension method in the daily development process to achieve rapid calling of the program.
- Transaction function inherits from
IDisposable - We usually need to use using internal to operate Revit during development. Achieve automatic disassembly
- We need to create a generic function
MTransactionand constrain it to theIDisposableinterface - Implement using keyword inside the above function to reduce repeated calls inside other functions, reduce code volume and reduce coupling
- Create function
TransactionHelperto encapsulate this reference, and call the intermediate function through third-party call to complete the call
Function Structure
1 | public static class MTransaction |
Call this method
1 | TransactionHelper.Execute(doc, c => |
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.




