当前位置:网站首页>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);
});
边栏推荐
猜你喜欢
C语言深度解剖——C语言关键字
TP-LINK 企业路由器 PPTP 配置
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
The harm of game unpacking and the importance of resource encryption
广州推进儿童友好城市建设,将探索学校周边200米设安全区域
Double pointeur en langage C - - modèle classique
MySQL learning record 11jdbcstatement object, SQL injection problem and Preparedstatement object
PLT in Matplotlib tight_ layout()
JVM 快速入门
电脑清理,删除的系统文件
随机推荐
The mysqlbinlog command uses
Charging interface docking tutorial of enterprise and micro service provider platform
FairGuard游戏加固:游戏出海热潮下,游戏安全面临新挑战
[MySQL] log
Promise 在uniapp的简单使用
Process of obtaining the electronic version of academic qualifications of xuexin.com
企微服务商平台收费接口对接教程
Leetcode skimming (5.29) hash table
How to conduct interface test? What are the precautions? Nanny level interpretation
The problem and possible causes of the robot's instantaneous return to the origin of the world coordinate during rviz simulation
2022.02.13 - NC003. Design LRU cache structure
hutool优雅解析URL链接并获取参数
pytorch训练好的模型在加载和保存过程中的问题
角色动画(Character Animation)的现状与趋势
China vanadium battery Market Research and future prospects report (2022 Edition)
Report on Market Research and investment prospects of China's silver powder industry (2022 Edition)
View computer devices in LAN
Revit 二次开发 HOF 方式调用transaction
[NVIDIA development board] FAQ (updated from time to time)
C語言雙指針——經典題型