Giter Club home page Giter Club logo

Comments (3)

pardeike avatar pardeike commented on May 25, 2024

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.

krafs avatar krafs commented on May 25, 2024

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.

pardeike avatar pardeike commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.