小编Ama*_*Ama的帖子

模块是否与SharedMembers-NotInheritable-PrivateNew类完全相同?

我可以在互联网上看到很多VB.Net模块与c#.Net Static Classes相同.我还可以读到接近a的东西Static Class是一个看起来像这样的类:

'NotInheritable so that no other class can be derived from it
Public NotInheritable Class MyAlmostStaticClass

    'Private Creator so that it cannot be instantiated
    Private Sub New()
    End Sub

    'Shared Members
    Public Shared Function MyStaticFunction() as String
        Return "Something"
    End Function

End Class
Run Code Online (Sandbox Code Playgroud)

我觉得这个代码很重要,可以起草,也可以阅读.使用Module这样的东西我会更舒服:

Public Module MyEquivalentStaticClass
    Public Function MyStaticFunction() as String
        Return "Something"
    End Function
End Module
Run Code Online (Sandbox Code Playgroud)

但是,如果Module您松散了一级Namespace层次结构,并且以下3个语句相同:

'Call through the Class Name is compulsory
Dim MyVar as …
Run Code Online (Sandbox Code Playgroud)

vb.net

6
推荐指数
2
解决办法
94
查看次数

在另一个类中声明一个类的目的是什么?

我来自VBA世界,将代码细分为类,名称空间和模块的选项是有限的.现在我刚刚进入了一个选项很多的世界,我感到迷茫.

我想知道在另一个类中声明一个类的目的是什么?(见下面的例子)

Class FirstClass
    Public OnePropertyInside As String
    Class SecondClass
        Public AnotherProperty As String
    End Class
End Class
Run Code Online (Sandbox Code Playgroud)

如果我创建FirstClass(例如myFirstClass)的新实例,SecondClass则不实例化.更为古怪(至少对我来说),是知识分子为我提供的myFirstClass.SecondClass.显然,因为类没有实例化,所以我无法访问它的任何成员.


那么,只有SecondClass包含shared成员时才有用吗?为了尝试回答这个问题,我在其中添加了一个共享成员SecondClass:

Class FirstClass
    Public OnePropertyInside As String
    Class SecondClass
        Public AnotherProperty As String
        Public Shared SharedProperty As String
    End Class
End Class
Run Code Online (Sandbox Code Playgroud)

我运行了一些带来次要问题的测试(参见代码中的注释)

Sub Main()       

    Dim myFirstClass As New FirstClass
    'Works as expected
    Console.WriteLine(myFirstClass.OneProperty)

    'What is the difference between the two lines below?
    Console.WriteLine(myFirstClass.SecondClass.SharedProperty)
    Console.WriteLine(FirstClass.SecondClass.SharedProperty)

    'This line …
Run Code Online (Sandbox Code Playgroud)

vb.net encapsulation class

4
推荐指数
1
解决办法
76
查看次数

识别对互操作库中对象的唯一引用(Doument.Paragraphs 等)

我希望能够识别两个互操作变量对象何时引用同一个“实际”对象。我所说的“实际”是指Microsoft Word文档中的给定段落或脚注。

中的示例:(注意答案也可以,问题与语言无关)

Imports Microsoft.Office.Interop

Sub Tests()

    Dim WordApp as Word.Application = Globals.ThisAddIn.Application         
    Dim ThisDoc as Word.Document = WordApp.ActiveDocument
    Dim ThisSelection As Word.Selection = ThisDoc .Application.Selection
    If ThisSelection.Range Is Nothing Then Exit Sub

    Dim SelectedPara As Word.Paragraph = ThisSelection.Range.Paragraphs.First


    For Each MyPara As Word.Paragraph In ThisDoc.Paragraphs

        'Reference equality: Never finds a match
        If MyPara.Equals(SelectedPara) Then MsgBox("Paragraph Found by ref") 

        'Property equality: Seems to works ok with .ParaID
        If MyPara.ParaID = SelectedPara.ParaID Then …
Run Code Online (Sandbox Code Playgroud)

c# vb.net vsto ms-word office-interop

2
推荐指数
1
解决办法
442
查看次数

测试证书不可信

我为 Word 和 Excel 开发 VSTO 解决方案。从昨天开始,由于没有明显的原因,我现在无法调试我的任何解决方案。即使当我尝试调试新的空白 VSTO 项目时,我也会遇到相同的症状。

当加载项启动时(通常在 Excel 或 Word 启动时),将显示以下内容:

System.Security.SecurityException:此应用程序中的自定义功能将不起作用,因为用于签署 ExcelAddIn1 部署清单的证书或其位置不受信任。请联系您的管理员以获得进一步帮助。

在此输入图像描述

Word 和 Excel 都会出现这种情况。我在 Windows 10 和 Office 365(即点即用版本)下从 Visual Studio 2017 进行调试。这是VS2017没有正确注册测试证书的问题吗?或者可能是我的 Windows 配置有问题(证书包含列表等)?

更新

更新和修复Visual Studio 2017没有任何效果。安装 VS2019 并使用新的空白 Excel VSTO 插件进行测试没有任何效果。使用 EV 代码签名证书(来自 Sectigo,仍然有效且过去多次使用)发布空白加载项也会产生同样的问题。

我现在怀疑这可能是由于部署清单分区造成的。如何调查清单的注册位置及其“有效”位置?这样我就可以验证两者是否匹配。

clickonce vsto code-signing

2
推荐指数
1
解决办法
4447
查看次数

RSA和OAEP:选择还是不选择哈希算法?

我正在实现一个非对称加密系统:

''' <summary>
''' A facade for a data asymmetrical encryption algorithm relying on a pair of public and private keys.
''' </summary>
Public Interface IAsymEncrypter

    ''' <summary>
    ''' The public key to rely upon for encrypting data. Under XML format.
    ''' </summary>
    ReadOnly Property PublicKeyXml As String

    ''' <summary>
    ''' The private key to rely upon for decrypting data. Under XML format.
    ''' <para>Also contains the public key.</para>
    ''' </summary>
    ReadOnly Property PrivateKeyXml As String

    ''' <summary>
    ''' Encrypts …
Run Code Online (Sandbox Code Playgroud)

.net vb.net encryption cryptography rsa

2
推荐指数
1
解决办法
3274
查看次数