什么是C#的CoClass属性呢? [英] What does the C# CoClass attribute do?

查看:1363
本文介绍了什么是C#的CoClass属性呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现的代码像在我们使用第三方库下面。

I found code something like the following in a 3rd party library we're using.

[CoClass(typeof(BlahClass))]
public interface Blah : IBlah
{
}

这是什么做的究竟是什么? MSDN文档没有照亮主体充分,我搞不懂。

What is this doing exactly? The msdn documentation didn't illuminate the subject sufficiently for me to follow.

推荐答案

据宣布,该接口胡说旨在通过一个特定的类来实现。这意味着,你可以方便说新布拉赫和运行时就知道要创建的对象 - 这通常不太可能与接口。

It declares that the interface Blah is intended to be implemented by a specific class. It means that you can conveniently say new Blah and the runtime will know what object to create - something that is not normally possible with an interface.

如果你看一下BlahClass生成的声明,它将大概有一个的Guid 与之相关的可以是用于创建一个COM对象的实例

If you look at the generated declaration for BlahClass, it will presumably have a Guid associated with it which can be used to create an instance of a COM object.

这篇关于什么是C#的CoClass属性呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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