当前位置:网站首页>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);
});
边栏推荐
- Colorlog combined with logging to print colored logs
- 目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
- Golang force buckle leetcode 1020 Number of enclaves
- Circular reference of ES6 module
- 【刷题】牛客网面试必刷TOP101
- IoT -- 解读物联网四层架构
- Research Report on supply and demand and development prospects of China's high purity aluminum market (2022 Edition)
- 2022 Inner Mongolia latest construction tower crane (construction special operation) simulation examination question bank and answers
- egg. JS project deployment online server
- Introduction to the differences between compiler options of GCC dynamic library FPIC and FPIC
猜你喜欢

The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower

Problems in loading and saving pytorch trained models

2. File operation - write
![[secretly kill little partner pytorch20 days -day01- example of structured data modeling process]](/img/ae/4e616882f6d68acdf8e885843e68a3.jpg)
[secretly kill little partner pytorch20 days -day01- example of structured data modeling process]

【MySQL】鎖

【MySQL】数据库的存储过程与存储函数通关教程(完整版)
![[MySQL] database stored procedure and storage function clearance tutorial (full version)](/img/27/e775e03b77c7195216bc50c5cbefb4.png)
[MySQL] database stored procedure and storage function clearance tutorial (full version)

leetcode刷题 (5.28) 哈希表

【ROS】usb_cam相机标定

C语言深度解剖——C语言关键字
随机推荐
IoT -- 解读物联网四层架构
Restful API design specification
MySQL learning record 10getting started with JDBC
Roguelike game into crack the hardest hit areas, how to break the bureau?
从表中名称映射关系修改视频名称
电脑F1-F12用途
Process of obtaining the electronic version of academic qualifications of xuexin.com
@JsonBackReference和@JsonManagedReference(解决对象中存在双向引用导致的无限递归)
Pointer advanced --- pointer array, array pointer
JS inheritance method
[cloud native topic -45]:kubesphere cloud Governance - Introduction and overall architecture of enterprise container platform based on kubernetes
如何进行接口测试测?有哪些注意事项?保姆级解读
JVM 快速入门
pytorch训练好的模型在加载和保存过程中的问题
指针进阶---指针数组,数组指针
Deep analysis of C language data storage in memory
Beijing invitation media
Function coritization
Summary of MySQL index failure scenarios
Is it safe to open an account in Zheshang futures?