当前位置:网站首页>Revit secondary development Hof method calls transaction
Revit secondary development Hof method calls transaction
2022-07-06 08:44:00 【Imkc】
Look again 《C# Functional programming 》 When I read a book HOF The concept of , I feel that this method can be used to sort out an expansion method in the process of daily development , Realize the rapid call of the program .
- Transaction Function inherited from
IDisposable - We usually need to use using Inside to Revit To operate . Realize automatic disassembly
- We need to create a generic function
MTransactionAnd bound inIDisposableInterface - Implement inside the above function using Keywords reduce repeated calls inside other functions , Reduce the amount of code and reduce coupling
- Create a function
TransactionHelperThis amplified reference encapsulates , Call intermediate functions through a third party to complete the call
Function structure
public static class MTransaction
{
public static void Using<TDisp>(TDisp disposable, Action<TDisp> f) where TDisp : IDisposable
{
using (disposable)
{
f(disposable);
}
}
}
public static class TransactionHelper
{
public static void Execute(Document doc, Action<IDisposable> f)
=> MTransaction.Using(new Transaction(doc, "create"), trans =>
{
trans.Start();
f(trans);
trans.Commit();
});
}
Call this method
TransactionHelper.Execute(doc, c =>
{
var line = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(2000 / 304.8, 2000 / 304.8, 0));
Wall w = Wall.Create(doc, line, new ElementId(311), false);
});
边栏推荐
- Modify the video name from the name mapping relationship in the table
- How to conduct interface test? What are the precautions? Nanny level interpretation
- vb.net 随窗口改变,缩放控件大小以及保持相对位置
- MySQL learning record 10getting started with JDBC
- @Jsonbackreference and @jsonmanagedreference (solve infinite recursion caused by bidirectional references in objects)
- sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
- The network model established by torch is displayed by torch viz
- TP-LINK enterprise router PPTP configuration
- The mysqlbinlog command uses
- 如何进行接口测试测?有哪些注意事项?保姆级解读
猜你喜欢
随机推荐
MySQL learning record 07 index (simple understanding)
egg. JS project deployment online server
Promise 在uniapp的简单使用
Sublime text in CONDA environment plt Show cannot pop up the problem of displaying pictures
ESP8266-RTOS物联网开发
JS inheritance method
vb.net 随窗口改变,缩放控件大小以及保持相对位置
China Light conveyor belt in-depth research and investment strategy report (2022 Edition)
Restful API design specification
pytorch训练好的模型在加载和保存过程中的问题
TCP/IP协议
visdom可视化实现与检查介绍
tree树的精准查询
Image, CV2 read the conversion and size resize change of numpy array of pictures
Bitwise logical operator
Sublime text using ctrl+b to run another program without closing other runs
Precise query of tree tree
R language uses the principal function of psych package to perform principal component analysis on the specified data set. PCA performs data dimensionality reduction (input as correlation matrix), cus
自动化测试框架有什么作用?上海专业第三方软件测试公司安利
深度剖析C语言指针
![[MySQL] log](/img/e9/1617122888c096cf6aba2bdb88f0ef.png)

![[MySQL] lock](/img/ce/9f8089da60d9b3a3f92a5e4eebfc13.png)






