当前位置:网站首页>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);
});
边栏推荐
- Deep analysis of C language pointer
- Swagger setting field required is mandatory
- Simple use of promise in uniapp
- Leetcode question brushing (5.31) string
- 企微服务商平台收费接口对接教程
- Using pkgbuild:: find in R language_ Rtools check whether rtools is available and use sys The which function checks whether make exists, installs it if not, and binds R and rtools with the writelines
- Sublime text in CONDA environment plt Show cannot pop up the problem of displaying pictures
- China polyether amine Market Forecast and investment strategy report (2022 Edition)
- sys. argv
- C語言雙指針——經典題型
猜你喜欢
![[embedded] cortex m4f DSP Library](/img/83/ab421d5cc18e907056ec2bdaeb7d5c.png)
[embedded] cortex m4f DSP Library

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

软件卸载时遇到trying to use is on a network resource that is unavailable

marathon-envs项目环境配置(强化学习模仿参考动作)

Fairguard game reinforcement: under the upsurge of game going to sea, game security is facing new challenges

swagger设置字段required必填

TP-LINK 企业路由器 PPTP 配置

Swagger setting field required is mandatory

Sublime text using ctrl+b to run another program without closing other runs

Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
随机推荐
Process of obtaining the electronic version of academic qualifications of xuexin.com
JVM performance tuning and practical basic theory - Part 1
[MySQL] lock
China's high purity aluminum target market status and investment forecast report (2022 Edition)
China Light conveyor belt in-depth research and investment strategy report (2022 Edition)
Current situation and trend of character animation
角色动画(Character Animation)的现状与趋势
win10系统中的截图,win+prtSc保存位置
Simple use of promise in uniapp
Golang force buckle leetcode 1020 Number of enclaves
MySQL learning record 11jdbcstatement object, SQL injection problem and Preparedstatement object
Function coritization
Research and investment forecast report of citronellol industry in China (2022 Edition)
查看局域网中电脑设备
MySQL learning record 10getting started with JDBC
【嵌入式】Cortex M4F DSP库
Deep analysis of C language pointer
Rviz仿真时遇到机器人瞬间回到世界坐标原点的问题及可能原因
JVM 快速入门
堆排序详解