当前位置:网站首页>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);
});
边栏推荐
- IOT -- interpreting the four tier architecture of the Internet of things
- The mysqlbinlog command uses
- Bitwise logical operator
- Leetcode question brushing (5.31) string
- egg. JS getting started navigation: installation, use and learning
- 【MySQL】鎖
- China's high purity aluminum target market status and investment forecast report (2022 Edition)
- Leetcode skimming (5.29) hash table
- visdom可视化实现与检查介绍
- VMware virtualization cluster
猜你喜欢
Sublime text in CONDA environment plt Show cannot pop up the problem of displaying pictures
Ruffian Heng embedded bimonthly, issue 49
Light of domestic games destroyed by cracking
Beijing invitation media
CISP-PTE实操练习讲解
[brush questions] top101 must be brushed in the interview of niuke.com
Double pointeur en langage C - - modèle classique
Deep analysis of C language pointer
PLT in Matplotlib tight_ layout()
Deep analysis of C language data storage in memory
随机推荐
pytorch训练好的模型在加载和保存过程中的问题
LDAP应用篇(4)Jenkins接入
What is CSRF (Cross Site Request Forgery)?
Fibonacci sequence
【MySQL】锁
The mysqlbinlog command uses
Leetcode question brushing (5.31) string
sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
查看局域网中电脑设备
Mobile Test Engineer occupation yyds dry goods inventory
延迟初始化和密封类
Visual implementation and inspection of visdom
Screenshot in win10 system, win+prtsc save location
Function coritization
Precise query of tree tree
Roguelike game into crack the hardest hit areas, how to break the bureau?
JVM performance tuning and practical basic theory - Part 1
Computer cleaning, deleted system files
IOT -- interpreting the four tier architecture of the Internet of things
ROS编译 调用第三方动态库(xxx.so)