实现在DLL中声明的功能 [英] Implementing function declared in dll

查看:61
本文介绍了实现在DLL中声明的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
其实我有一个dll名称为demodll.
其中包含以下代码:

 使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;

命名空间 demoDll
{
    公共  Class1
    {
        公共 虚拟  int  ADDNumbers( int  a, int  b, int  c)
        {
            返回  0 ;

        }
    }

} 



现在,我将此dll添加到另一个点网应用程序中作为参考.
我想在我的点网应用程序中覆盖此ADDNumbers函数.
我想为此功能编写实现.
我该怎么办?
任何人都有任何示例代码或我可以通过的任何教程..
请帮忙..
愿上帝保佑大家
谢谢..:)

解决方案

引用该DLL在另一个项目中.

使用名称空间(使用demoDll).

扩展类(公共类ImplementingClass:Class1)并像往常一样覆盖该方法

public class ImplementingClass : Class1 {
 public override int ADDNumbers(int a, int b, int c){ ... }
}



看来您正在尝试执行纯虚函数"(C ++术语),在这种情况下,应在DLL中使方法抽象而不是虚方法,并可能使Class1成为接口.


昨天有一个正确的答案.现在它消失了,所以我要在这里复制它:

将您的in-dll代码更改为

 公共 抽象  class  Class1
{
    公共 抽象  int  ADDNumbers( int  a, int  b, int  c);
} 


这根本不提供AddNumbers()的任何实现,但是强制您在每个派生类中重写它.

您的实际应用程序包括dll.在此进行子类化,包括AddNumbers()的实现.

如果您只希望从Class1获得,也可以将其变成 interface 而不是一个类.这将允许您的应用程序中的类从其他派生,并且同时实现此接口.

哦,派生类就像

 公共  class  Class2:Class1
{
    // 编译器将不允许任何Class1派生的
    // 类,除非它实现AddNumbers()
    公共 覆盖  int  ADDNumbers( int  a, int  b, int  c)
    {
        返回(a + b + c);
    }
} 


hi all
Actually i have one dll name demodll.
which contains this code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace demoDll
{
    public class Class1
    {
        public virtual int ADDNumbers(int a, int b,int c)
        {
            return 0;

        }
    }

}



now i am adding this dll into another dot net application as a reference.
i want to override this ADDNumbers function in my dot net application.
i want to write implementation for this function.
how can i do it??
Anyone have any sample code or any tutorial which i can go through..
please help..
god bless you all
thank you..:)

解决方案

Reference that DLL in another project.

Use the namespace (using demoDll).

Extend the class (public class ImplementingClass : Class1) and override the method as normal

public class ImplementingClass : Class1 {
 public override int ADDNumbers(int a, int b, int c){ ... }
}



It looks like you''re trying to do a ''pure virtual function'' (C++ terminology) in which case you should make the method abstract, not virtual, in the DLL, and likely make Class1 an interface instead.


Yesterday, there was a correct answer. Now it''s gone, so I''m going to reproduce it here:

Change your in-dll-code to

public abstract class Class1
{
    public abstract int ADDNumbers(int a, int b,int c);
}


This doesn''t provide any implementation for AddNumbers() at all, but is enforcing that you override it in every derived class.

Your actual application includes the dll. Do the subclassing there including the implementation of AddNumbers().

If that''s all you want from Class1, you can also turn it into an interface instead of a class. That would allow the classes in your application to derive from something else and implement this interface at the same time.

Oh, and the derived class would be something like

public class Class2 : Class1
{
    // The compiler will not allow any Class1-derived
    //   class unless it implements AddNumbers()
    public override int ADDNumbers(int a, int b, int c)
    {
        return( a + b + c);
    }
}


这篇关于实现在DLL中声明的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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