当前位置:网站首页>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);
});
边栏推荐
- Introduction to the differences between compiler options of GCC dynamic library FPIC and FPIC
- PC easy to use essential software (used)
- sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
- TCP/IP协议
- pytorch训练好的模型在加载和保存过程中的问题
- R language ggplot2 visualization, custom ggplot2 visualization image legend background color of legend
- win10系统中的截图,win+prtSc保存位置
- 被破解毁掉的国产游戏之光
- Function coritization
- gcc动态库fPIC和fpic编译选项差异介绍
猜你喜欢
TP-LINK enterprise router PPTP configuration
Indentation of tabs and spaces when writing programs for sublime text
2022.02.13 - 238. Maximum number of "balloons"
【MySQL】锁
pytorch训练好的模型在加载和保存过程中的问题
C language double pointer -- classic question type
704 二分查找
[cloud native topic -45]:kubesphere cloud Governance - Introduction and overall architecture of enterprise container platform based on kubernetes
Generator parameters incoming parameters
游戏解包的危害及资源加密的重要性
随机推荐
@Jsonbackreference and @jsonmanagedreference (solve infinite recursion caused by bidirectional references in objects)
sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
swagger设置字段required必填
Warning in install. packages : package ‘RGtk2’ is not available for this version of R
Leetcode question brushing (5.28) hash table
TCP/IP协议
[MySQL] log
China dihydrolaurenol market forecast and investment strategy report (2022 Edition)
China Light conveyor belt in-depth research and investment strategy report (2022 Edition)
JVM 快速入门
超高效!Swagger-Yapi的秘密
JS pure function
查看局域网中电脑设备
ROS compilation calls the third-party dynamic library (xxx.so)
visdom可视化实现与检查介绍
egg. JS project deployment online server
ROS编译 调用第三方动态库(xxx.so)
Deep anatomy of C language -- C language keywords
如何有效地进行自动化测试?
PC easy to use essential software (used)