当前位置:网站首页>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
MTransaction
And bound inIDisposable
Interface - Implement inside the above function using Keywords reduce repeated calls inside other functions , Reduce the amount of code and reduce coupling
- Create a function
TransactionHelper
This 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);
});
边栏推荐
- 【嵌入式】Cortex M4F DSP库
- Is it safe to open an account in Zheshang futures?
- Verrouillage [MySQL]
- @JsonBackReference和@JsonManagedReference(解决对象中存在双向引用导致的无限递归)
- China Light conveyor belt in-depth research and investment strategy report (2022 Edition)
- 如何有效地进行自动化测试?
- vb.net 随窗口改变,缩放控件大小以及保持相对位置
- [MySQL] log
- 2022.02.13 - NC004. Print number of loops
- 【嵌入式】使用JLINK RTT打印log
猜你喜欢
JVM quick start
Fairguard game reinforcement: under the upsurge of game going to sea, game security is facing new challenges
PC easy to use essential software (used)
查看局域网中电脑设备
Verrouillage [MySQL]
【嵌入式】使用JLINK RTT打印log
visdom可视化实现与检查介绍
C語言雙指針——經典題型
Generator parameters incoming parameters
角色动画(Character Animation)的现状与趋势
随机推荐
tree树的精准查询
JVM performance tuning and practical basic theory - Part 1
企微服务商平台收费接口对接教程
win10系统中的截图,win+prtSc保存位置
vb.net 随窗口改变,缩放控件大小以及保持相对位置
Trying to use is on a network resource that is unavailable
JS native implementation shuttle box
Chrome浏览器的crash问题
sublime text中conda环境中plt.show无法弹出显示图片的问题
Crash problem of Chrome browser
Navicat premium create MySQL create stored procedure
延迟初始化和密封类
View computer devices in LAN
Problems in loading and saving pytorch trained models
egg. JS project deployment online server
China Light conveyor belt in-depth research and investment strategy report (2022 Edition)
704 binary search
C语言深度解剖——C语言关键字
704 二分查找
Synchronized solves problems caused by sharing