VB.NET会自动生成ComClass属性和guids吗? [英] Will VB.NET automatically generate ComClass attribute and guids?

查看:150
本文介绍了VB.NET会自动生成ComClass属性和guids吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些VB.NET代码,它们显式创建了三个GUID常量,并在类的ComClass属性中使用它们。在过去,我通过在项目选项中选中Make COM-Visible和Register for COM interop选项来编写COM感知类。这个明确的代码是不是没有必要,还是在做这些两个选项之外的事情?这是一段代码:

I've run across some VB.NET code that explicitly creates three GUID constants and uses them in a class's ComClass attribute. I've written COM-aware classes in the past just by checking the "Make COM-Visible" and "Register for COM interop" options in the project options. Is this explicit code simply unnecessary, or is it doing something above-and-beyond what those two options do? Here's a snippet:

<ComClass(MenuHandler.ClassId, MenuHandler.InterfaceId, MenuHandler.EventsId)> _
Public Class MenuHandler
    Public Const ClassId As String = "A2204623-A902-44d4-B524-FDFFCD176E53"
    Public Const InterfaceId As String = "3449CA8B-16DF-4a61-8BAB-DFF27AE70F5E"
    Public Const EventsId As String = "06C156DD-0ABA-437e-9EE0-C1CE2CA34033"
End Class


推荐答案

通过显式地将属性放在你想要暴露的类和枚举中,你可以防止类似辅助类,内部工具或内部类的东西裸露。这是从微软推荐的方式做的...当他们推荐的东西,它通常意味着,如果你不这样做,你的程序可能会在未来打破。 :)

By explicitly putting attributes on the classes and enumerations that you want exposed you can prevent things like helper classes, internal tools, or internal classes that should not be exposed from being exposed. This is the recommended way from Microsoft to do it...and when they recommend something, it usually means that if you don't do it, your program may break in the future. :)

检查使COM可见和注册COM interop是创建COM可见对象的简单方法,但不推荐。这将增加每个类可见的开销 - 即使是你可能不想要的类。

Checking "make COM visible" and "register for COM interop" is the simple method for making COM visible objects, but is not recommended. This will add the overhead for every class visible - even ones that you may not want.

这篇关于VB.NET会自动生成ComClass属性和guids吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆