当前位置:网站首页>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);
});
边栏推荐
- 移位运算符
- TCP/IP协议
- Restful API design specification
- View computer devices in LAN
- China Light conveyor belt in-depth research and investment strategy report (2022 Edition)
- 有效提高软件产品质量,就找第三方软件测评机构
- ROS编译 调用第三方动态库(xxx.so)
- Beijing invitation media
- Target detection - pytorch uses mobilenet series (V1, V2, V3) to build yolov4 target detection platform
- MySQL learning record 11jdbcstatement object, SQL injection problem and Preparedstatement object
猜你喜欢

延迟初始化和密封类

Deep analysis of C language data storage in memory

【ROS】usb_cam相机标定

Bottom up - physical layer

2022.02.13 - NC004. Print number of loops
![[MySQL] log](/img/e9/1617122888c096cf6aba2bdb88f0ef.png)
[MySQL] log

被破解毁掉的国产游戏之光

egg. JS getting started navigation: installation, use and learning

Mobile phones and computers on the same LAN access each other, IIS settings

MySQL learning record 11jdbcstatement object, SQL injection problem and Preparedstatement object
随机推荐
China high purity silver nitrate Market Research and investment strategy report (2022 Edition)
ROS compilation calls the third-party dynamic library (xxx.so)
Function coritization
China's high purity aluminum target market status and investment forecast report (2022 Edition)
JVM 快速入门
电脑清理,删除的系统文件
【ROS】usb_cam相机标定
704 二分查找
有效提高软件产品质量,就找第三方软件测评机构
[brush questions] top101 must be brushed in the interview of niuke.com
Light of domestic games destroyed by cracking
Bottom up - physical layer
Trying to use is on a network resource that is unavailable
Mobile phones and computers on the same LAN access each other, IIS settings
查看局域网中电脑设备
Swagger setting field required is mandatory
pcd转ply后在meshlab无法打开,提示 Error details: Unespected eof
Verrouillage [MySQL]
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
C语言双指针——经典题型