Is it possible to override a method in a class in a DLL file?

I have included a DLL file in my windows form project. 1. Is it possible to completely override a specific class? 2. Is it possible to add a new method to a specific class in a DLL file? 3. Is it possible to override a method in a class in a dll?

Alternatives that I would rather avoid: I know that I can use extension methods to create static new methods. I can also inherit from a specific class and then add new methods to the derived class.

What I am trying to achieve: I need to create a project now and add it to a larger project as a dll file. but we were told that next month we will need to add more functionality to the original project. I am trying to figure out how to do this. the smaller project is based on the mvc project.

+1


source to share


2 answers


You can override a virtual method that you inherit from a class in a class library. You do this every time you override object.ToString()

for example!

You can't "redefine the entire class" though - I don't know what that means. Likewise, you cannot add a method to an existing class, although you can:

  • Use pretend extension methods to add another method (but not state and no properties)
  • Dump the class (if not sealed) and declare your own additional methods


If you could tell us what you are trying to achieve, it would be easier to advise you on how to proceed.

EDIT: When you need to add more functionality to your original project, just add it to your original project. Is there a reason why you can't change this project afterwards?

+2


source


What I am trying to achieve: I have to create a project and add it to a larger project as a dll file. but we were told that we would need to add more functionality to the original project next month. I am trying to figure out the best way to go this. the smaller project is based on mvc.



The current best practice is to use inversion of control (like ninject ) for this kind of thing, if you have a central place for all your dependencies, you can hook them up however you like at runtime, intercepting the chunks as you wish.

0


source







All Articles