执行C#接口 [英] Executing a C# Interface

查看:89
本文介绍了执行C#接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我需要一些帮助来了解界面.我了解如何编写代码,了解如何以及为什么需要在底层类中实现接口中公开的方法,道具等.而且我知道如何继承接口并执行方法,道具等.

我遇到接口问题的地方是IObjectSafety.我有一个C#对象,需要从类似javascript的脚本中调用.我暴露了COM,一切都很好.我当然会遇到无法创建对象的错误,除非我降低安全性以允许创建不安全的对象.所以...

我已经阅读了几篇大体相同的文章.我已经创建了IObjectSafety接口,并在派生类中放入了requsite方法.但是!! ...接口方法如何执行???这些教程都没有显示从构造函数调用方法?在对象创建期间,如何调用IObjectSafety SetInterfaceSafetyOptions?这些教程要么缺少关键要素,要么我很可能是我.

谢谢您的帮助

Hello,

I need a little help understanding interfaces. I understand how to code them, I understand how and why the methods, props, etc. exposed in the interface need to be implemented in the underlying class. And I know how to inherit an interface and thus execute the methods, props etc.

Where I am having my interface problem is with IObjectSafety. I have a C# object that needs to be called from script like javascript. I exposed COM and all is well. I of course get the can't create object error unless I lower the security to allow creation of unsafe objects. So...

I have read several articles all generally the same. I have created the IObjectSafety interface and put in the requsite methods in the derived class. BUT!!!....how does the interface methods get executed??? None of these tutorials have shown calling the methods from the constructor? How, during object creation, does the IObjectSafety SetInterfaceSafetyOptions get called? Either these tutorials are missing a key ingredient or I am....most likely me.

Thank You for your assistance

推荐答案

但是!!!接口方法如何执行??
BUT!!!....how does the interface methods get executed???

接口不具有方法的实现,而仅定义合同.因此,接口方法将无法执行,因为按照接口的定义,它就不需要执行.

但是,如果您创建一个实现接口定义的协定的对象,则您可以像调用其他方法一样通过调用该方法在派生对象中执行创建实现.

您可以参考本文以获得更多帮助:http://msdn.microsoft.com/en-us/library/87d83y5b%28VS.71%29.aspx

An interface does not have an implementation of methods, but rather just defines a contract. Therefore it would be impossible for a interface methods to get executed because by the very definition of an interface it has nothing to execute.

However if you create an object that implements the contract defined by the interface, then you could execute the implementation create in your derived object by calling the method like you would any other method.

You may refer to this article for further assistance: http://msdn.microsoft.com/en-us/library/87d83y5b%28VS.71%29.aspx


这篇关于执行C#接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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