当前位置:网站首页>Revit 二次开发 HOF 方式调用transaction
Revit 二次开发 HOF 方式调用transaction
2022-07-06 08:37:00 【Imkc】
再看《C#函数式编程》一书的时候看到HOF的概念,感觉在日常开发的过程中可以使用此方式整理一个拓展方法,实现程序的快速调用。
- Transaction函数继承自
IDisposable - 我们平时开发需要使用using内部对Revit进行操作。实现自动拆卸
- 我们需要创建一个泛型函数
MTransaction并约束在IDisposable接口 - 在上述函数内部实现using关键词减少其他函数内部的反复调用,减少代码量降低耦合性
- 创建函数
TransactionHelper对此放大引用封装,通过第三方调用中间函数即可完成调用
函数结构
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();
});
}
调用此方法
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);
});
边栏推荐
- Trying to use is on a network resource that is unavailable
- Zhong Xuegao, who cannot be melted, cannot escape the life cycle of online celebrity products
- Roguelike游戏成破解重灾区,如何破局?
- Leetcode question brushing (5.31) string
- MySQL learning records 12jdbc operation transactions
- [2022 广东省赛M] 拉格朗日插值 (多元函数极值 分治NTT)
- Golang force buckle leetcode 1020 Number of enclaves
- 【MySQL】锁
- [MySQL] lock
- 2022.02.13 - 238. Maximum number of "balloons"
猜你喜欢

C language double pointer -- classic question type

CISP-PTE实操练习讲解

JVM performance tuning and practical basic theory - Part 1

2022 Inner Mongolia latest construction tower crane (construction special operation) simulation examination question bank and answers

企微服务商平台收费接口对接教程

On the day of resignation, jd.com deleted the database and ran away, and the programmer was sentenced
![[brush questions] top101 must be brushed in the interview of niuke.com](/img/55/5ca957e65d48e19dbac8043e89e7d9.png)
[brush questions] top101 must be brushed in the interview of niuke.com

Deep learning: derivation of shallow neural networks and deep neural networks

C語言雙指針——經典題型

2. File operation - write
随机推荐
Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
[brush questions] top101 must be brushed in the interview of niuke.com
The resources of underground pipe holes are tight, and the air blowing micro cable is not fragrant?
visdom可视化实现与检查介绍
[MySQL] lock
logback1.3. X configuration details and Practice
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
Generator parameters incoming parameters
sys.argv
Computer cleaning, deleted system files
Browser thread
MySQL learning records 12jdbc operation transactions
电脑清理,删除的系统文件
swagger设置字段required必填
VMware 虚拟化集群
2022.02.13 - NC002. sort
pcd转ply后在meshlab无法打开,提示 Error details: Unespected eof
Is it safe to open an account in Zheshang futures?
Circular reference of ES6 module
Report on Market Research and investment prospects of China's silver powder industry (2022 Edition)