对象数据类型是对的吗? [英] Is Object Datatype right?

查看:67
本文介绍了对象数据类型是对的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我有两个项目 - 一个是exe&另一个是dll。我将一个dll项目的引用添加到exe,以便它可以访问dll项目的类型。现在在我的dll项目中,我的代码需要引用exe项目;这是不可能的,因为它会导致循环依赖。因此,我正在做的就是我将exe'的类型称为例如exe项目的MDIForm到数据类型为Object 的dll项目。现在我可以愉快地访问dll项目中所有MDIForm的成员。

我的问题:

Hi there,

I''ve two projects - one is an exe & the other is a dll. I add a reference of the dll project to the exe so that it can access dll project''s types. Now in my dll project I''ve code which requires reference to the exe project; this is not possible as it would result in circular dependency. Hence all I''m doing is I''m passing exe''s type say for example the MDIForm of the exe project to the dll project with datatype being Object. Now I can happily access all the MDIForm''s members in the dll project.

My question:

  1. 是否可以将MDIForm声明为对象 dll项目中的数据类型?
  2. 使用 Object 数据类型的缺点是我在编码时看不到它的成员,即intellisense没有显示MDIForm的成员。有没有办法将它强制转换为确切的类型?
  1. Is it okay to declare the MDIForm as Object datatype in the dll project?
  2. The disadvantage of using the Object datatype is that I cannot see its members while coding i.e. intellisense doesn''t shows the MDIForm''s members. Is there a way to typecast it to the exact type?



谢谢,

Aads


Thanks,
Aads

推荐答案

有一种方法可以对您作为对象传递的MDI表单进行类型化。


您只需提及具有Form类型的对象。因此intellisense将显示MDI表单对象的成员。


例如:

C#:

string formName =((Form )mdiFormObj).Name;
There is a way to typecase your MDI form that you have passed as object.

You just mention the object with the type of Form. So intellisense will show the members of the MDI form object.

Eg:
C#:
string formName=((Form)mdiFormObj).Name;


感谢您的快速回复。


如果我将其类型化为Form,它只会显示标准表单成员不是我写的那个。例如:我可能已经用名称AddTwoNumbers编写了一个公共函数,它不会出现在intellisense中,因为它不是标准表单的成员,而是我的类的成员。我希望这个成员显示在intellisense中。实际上它可以是任何用户定义的类。


希望现在很清楚。


谢谢,

Aads
Thanks for your quick reply.

If I typecast it to Form, It would only show the standard form members not the one which I have written. For example: I might have written a public function by name AddTwoNumbers, which would not appear in the intellisense as it is not a member of a standard form but the member of my class. I want this member to be displayed in the intellisense. In fact it could be any user defined class for that matter.

Hope now its clear.

Thanks,
Aads


也许您应该考虑将所有自定义函数声明为接口(或其他东西)并将其保存在DLL中。

所以你可以以这种方式引用函数?
Perhaps you should consider making all of your custom functions declared as an interface(or something) and keep that in the DLL.
So you can reference the functions that way?


这篇关于对象数据类型是对的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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