I need to update some .NET assembly in my project.
I've checked decompiled codes and saw that one method from the assembly of new version has time-consuming logic.
For example, assembly X.1 has some internal class Y. I need to update assembly to version X.2, but there are time-consuming changes in Y class.
Example:
X.1
internal class Y
{
public void Z(){
Method1();
Method2();
}
}
X.2
internal class Y
{
public void Z(){
Method1();
Method2();
TimeConsumingMethod3();
}
}
I need to run method Z without 'TimeConsumingMethod3()'.
Is it possible to modify only one public method in internal class from assembly by reflection or in another way?
Based on the OP, the answer is no.
Reflection enables you to examine APIs at run-time, in order to get type information about objects, methods, properties, etc. You can also create objects and run methods, including those that are
privateorinternal. Additionally, you can generate new 'code' at run time, using a part of .NET Reflection usually known as Reflection Emit.To my knowledge you can't change existing code using Reflection.
There are other low-level APIs that will enable you to do that (at least on .NET Framework), but IIRC these require you to write code in C++.
Since it sounds as though you've already decompiled the code, you may be able to remove the 'offending' line of code and recompile the code. Before you do that, however, consider if the library's licence allows that.
Also consider whether that time-consuming change isn't there for a good reason.
Finally, if this is open source or a package owned by another team in your organization, consider discussing with the package owner if there's a way to disable the time-consuming behaviour.