首页 > 编程语言 >Aveva Marine VBNET 编程系列-封装一个类

Aveva Marine VBNET 编程系列-封装一个类

时间:2023-09-30 09:33:08浏览次数:57  
标签:End Sub Dispose Aveva disposing VBNET Marine

由于AM的marapi的大部分类实现了IDisposable接口,所有避免内存过大,用了一般需要dispose下

微软官方的解释:

https://learn.microsoft.com/zh-cn/dotnet/api/system.idisposable?view=net-7.0

 

以下是MarDrafting类的定义,很显然它实现了IDisposable接口

 

Imports System.Reflection

Imports Aveva.Marine.Drafting
Imports Aveva.Marine.UI ' marAPI.dll
Imports Aveva.Marine.Utility ' marAPI.dll
Public Class AmEnvironment
    Implements IDisposable

    Private disposedValue As Boolean
    Public Property DraftApp As New MarDrafting
    Public Property MarUI As New MarUi
    Public Property MarUtility As New MarUtil
    Sub New()

    End Sub
    Protected Overridable Sub Dispose(disposing As Boolean)
        If Not disposedValue Then
            If disposing Then

                Dim t As Type = Me.GetType()
                Dim pros = t.GetProperties().Where(Function(p) p.PropertyType.Namespace IsNot Nothing And p.PropertyType.Namespace.StartsWith("Aveva.Marine."))
                For Each pi As PropertyInfo In pros
                    Dim tp = pi.PropertyType
                    Dim obj As IDisposable = pi.GetValue(Me, Nothing)
                    obj.Dispose()
                Next
                ' TODO: 释放托管状态(托管对象)
            End If

            ' TODO: 释放未托管的资源(未托管的对象)并重写终结器
            ' TODO: 将大型字段设置为 null
            disposedValue = True
        End If
    End Sub

    ' ' TODO: 仅当“Dispose(disposing As Boolean)”拥有用于释放未托管资源的代码时才替代终结器
    ' Protected Overrides Sub Finalize()
    '     ' 不要更改此代码。请将清理代码放入“Dispose(disposing As Boolean)”方法中
    '     Dispose(disposing:=False)
    '     MyBase.Finalize()
    ' End Sub

    Public Sub Dispose() Implements IDisposable.Dispose
        ' 不要更改此代码。请将清理代码放入“Dispose(disposing As Boolean)”方法中
        Dispose(disposing:=True)
        GC.SuppressFinalize(Me)
    End Sub
End Class

使用方法

 

标签:End,Sub,Dispose,Aveva,disposing,VBNET,Marine
From: https://www.cnblogs.com/NanShengBlogs/p/17737621.html

相关文章

  • Aveva Marine VBNET 编程系列-创建曲线
    显现的效果 代码实现:<MyAmFunctionAtt(NameOf(绘图控制),NameOf(新建曲线))>PublicSub新建曲线(wmAsWindowManager)DimdraftAppAsNewMarDraftingDimuiAsNewMarUi'ImportsAveva.Marine.UIDimutilyAsNewMarUtil'ImportsA......
  • Aveva Marine VBNET 编程系列-新建图纸,创建文字
    根据MarApi,创建图形文件,新建文字ImportsAveva.ApplicationFramework.PresentationImportsAveva.Marine.Drafting'marAPI.dllPublicClass绘图控制<MyAmFunctionAtt(NameOf(绘图控制),NameOf(新建图纸))>PublicSub新建图纸(wmAsWindowManager)Di......
  • Aveva Marine VBNET 编程系列-修改程序快捷键
    修改HullDesign程序的主题以及菜单项的快捷键 引用的dll文件下面的是代码和快捷键配置文件:https://files.cnblogs.com/files/NanShengBlogs/AMShortCut.HullDesign.zip?t=1695908179&download=trueImportsAveva.ApplicationFramework.PresentationImportsAveva.Applic......
  • Aveva Marine VBNET 编程系列-搭建开发框架
    引用的DllAveva.ApplicationFramework.dllAveva.ApplicationFramework.Presentation菜单展示效果创建Attribute,用于反射来动态创建菜单,不用每次都去写commandPublicClassMyAmFunctionAttInheritsAttributePrivate_menuNameAsStringPublicPropertyM......
  • VBNET AUTOCAD 单行文字OBB有向包围盒的计算
    遇到要求单行文字包围和的需求,发现AutoCAD自带的算法仅能求出正交包围盒,如下图所示的粉色矩形我想获取下图下图所示蓝色矩形的部分及OBB计算方法图形示例:下面是完整的代码,其中求D点的坐标p1涉及到向量定比分点公式<CommandMethod(NameOf(TT_SingleTextOBB))>SubTT......
  • Tokio Marine & Nichido Fire Insurance Programming Contest 2020
    A-Nickname直接输出前三个字符。代码:#include<iostream>#include<cstdio>usingnamespacestd;constintN=25;chars[N];intmain(){ scanf("%s",s+1); printf("%c%c%c",s[1],s[2],s[3]); return0;}B-Tag如果\(v\leqw\),则显然不......
  • c# aveva marine link folder
    publicclassLinkWorld{publicstaticDbElementLinkWLD=>Aveva.Pdms.Database.DbType.Design.FindElements(DbElementTypeInstance.LINKWLD).FirstOrDefault();}publicclassLinkDescription{publicDbElementCurElement{g......
  • Submarine Spark Security Plugin介绍(0.6.0版本)
    参考https://submarine.apache.org/zh-cn/docs/0.6.0/userDocs/submarine-security/spark-security/从ranger的github地址https://github.com/apache/ranger中可以发现当......
  • c# aveva marine 批量导出图纸到dxf格式
    获取图纸数据库查看代码publicstaticDictionary<string,List<DbElement>>GetDbElements(DbTypedbtype){Dictionary<string,List<DbElement......
  • C# AVEVA PDMS 修改快捷键
    修改快捷键和提示文件 提取菜单栏按钮publicstaticList<ButtonToolImpl>GetButtonImpls(thisMenuToolImplmtl){List<ButtonT......