Git Product home page Git Product logo

Comments (5)

ugaya40 avatar ugaya40 commented on July 3, 2024

ccc0934 でおそらく治ったと思いますが、Nugetなどバージョンを上げていないので手動でアセンブリ置換などをお願いできましょうでしょうか?

from livet.

veigr avatar veigr commented on July 3, 2024

ありがとうございます(サンプルコード動かしたやつコピペしたつもりだったんですが何故か動かないやつで申し訳ないです)。

確認しましたところ、 ccc0934 の修正ではメソッドに定義された引数の型が interface の場合に対応できないようです。

if ((!parameters[0].ParameterType.IsAssignableFrom(_argumentType))) return false;

であれば大丈夫そうであることは確認しましたが、いかがでしょうか?

from livet.

ugaya40 avatar ugaya40 commented on July 3, 2024

今度こそこれで治ったかと・・ ad6b43f

if (parameters[0].ParameterType.IsInterface)
{
    if (!newArgumentType.GetInterfaces().Contains(parameters[0].ParameterType)) return false;
}
else
{
    if ((!_argumentType.IsSubclassOf(parameters[0].ParameterType)) && (_argumentType != parameters[0].ParameterType)) return false;
}

にて今まで起きてた問題全部解決したかと思います。

また、いただいたコードの修正版

class Program
{
    static void Main(string[] args)
    {
        TestNormal();
        TestBinder();
    }

    private static void TestNormal()
    {
        // MethodBinderWithArgument を使わない通常の呼び出し
        Super calleeArg = null;
        var test = new Test(x => calleeArg = x);
        var callerArg = new Sub();
        test.TestMethod(callerArg);
        Console.WriteLine(callerArg == calleeArg);  // True
        test.TestMethod2(new Other());
    }

    private static void TestBinder()
    {
        // MethodBinderWithArgument を使った呼び出し
        Super calleeArg = null;
        var test = new Test(x => calleeArg = x);
        var binder = new MethodBinderWithArgument();
        var callerArg = new Sub();
        binder.Invoke(test, "TestMethod", callerArg);    // ArgumentException となる
        Console.WriteLine(callerArg == calleeArg);
        binder.Invoke(test,"TestMethod2",new Other());
    }
}

interface TestInterface
{

}

class Test
{
    private readonly Action<Super> action;

    public Test(Action<Super> action)
    {
        this.action = action;
    }

    public void TestMethod(Super arg) => this.action?.Invoke(arg);
    public void TestMethod2(TestInterface t) => this.action?.Invoke(null);
}
class Super { }
class Sub : Super { }
class Other : TestInterface { }

にて動作確認いたしました><

from livet.

veigr avatar veigr commented on July 3, 2024

確認しました。
これで問題ないように思います。
修正ありがとうございました。

from livet.

ugaya40 avatar ugaya40 commented on July 3, 2024

ありがとうございました!

from livet.

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.