Comments (3)
The reason is that reflections do not work well with inheritance. Its the same reason that does not allow you to call a base method on a child instance if you don't let the compiler do it. That includes casting, ordinary reflection and delegates. It's the reason Harmony has a reverse patch. I extended your code to demonstrate this effect:
public class Parent
{
public virtual void Hello() { Console.WriteLine("PARENT"); }
}
public class Child : Parent
{
public override void Hello() { Console.WriteLine("CHILD"); }
}
parentHello.Invoke(new Parent(), null);
parentHello.Invoke(new Child(), null); // should log PARENT but logsCHILD
childHello.Invoke(new Child(), null);
SymbolExtension uses reflection and thus cannot choose which level of overwrite it should get.
from harmony.
Maybe I've misunderstood the use of SymbolExtensions
then. Is SymbolExtensions
not for getting a MethodInfo
on a given type? It doesn't need to determine the level of the overwrite to return, I am telling it to return the one from Child
.
This gets me what I expect.
MethodInfo hello1 = typeof(Child).GetMethod("Hello");
And this call has all the same amount of information, so I feel like it should be able to give the same result, no?
MethodInfo hello2 = SymbolExtensions.GetMethodInfo<Child>(x => x.Hello());
Or is this not the purpose of SymbolExtensions
? It's not an alternative to Reflection for getting a MethodInfo
?
from harmony.
The purpose is the same. The technical limitations are not the same. SymbolExtensions basically wrap a super simple concept and there is no way to improve that: < https://github.com/pardeike/Harmony/blob/669729f618e90ecf7fe943f7ed70f8150216dc5a/Harmony/Tools/SymbolExtensions.cs#L47>
from harmony.
Related Issues (20)
- A crash after hook:The object's current state invalidates the operation HOT 2
- Harmony fails to patch method and throws exception in exported Godot build HOT 13
- NuGet Package reference assembly conflict HOT 8
- ModuleInitializerAttribute HOT 1
- RtDynamicMethod get MetadataToken throws InvalidOperationException HOT 2
- Patch on .net 7&8 throw TypeLoadException while debugging HOT 18
- Harmony 3.0: Utility Epic
- Investigate Testing the NuGet Package Directly HOT 3
- Add a Release Pipeline
- Hook exception: System.Exception: Cannot get result from void method System.Void HOT 2
- How to patch method of base class? HOT 1
- When applying a patch fails, the replacement's IL is not printed to the debug log HOT 2
- System.Exception: Parameter "xx" not found in method HOT 10
- can lib work in arm64? HOT 2
- Companion project promotion: Harmony Tools HOT 3
- PatchFunctions.UpdateWrapper NotImplementedException on MacOS HOT 11
- Harmony.Patch() is a bit slow. HOT 2
- 'CORINFO_METHOD_INFO' from assembly 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. HOT 4
- I try to hook DateTime.UtcNow but it throw exception HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from harmony.