Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.
This repository was archived by the owner on Aug 24, 2022. It is now read-only.

Delegate with detached instance method #624

Description

@iskiselev

In .Net, you can create delegate to instance method that will accept object on which you want call it as first delegate call argument. It is not supported in JSIL. Here is small test case:

using System;
using System.Runtime.InteropServices;

public static class Program
{
    public static void Main()
    {
        var d = (Action<ClassWithInstanceMember>)Delegate.CreateDelegate(typeof(Action<ClassWithInstanceMember>), null, typeof(ClassWithInstanceMember).GetMethod("Run"));
        d(new ClassWithInstanceMember(1));
        d(null);
    }
}

public class ClassWithInstanceMember
{
    public int _value;

    public ClassWithInstanceMember(int value)
    {
        _value = value;
    }

    public void Run()
    {
        if (this != null)
        {
            Console.WriteLine("this: " + _value);
        }
        else
        {
            Console.WriteLine("this==null ");
        }
    }
}

I will work on this issue, as it is requirement for Expression Interpreter work with instance methods. Full test case should check:

  • Non-generic methods in non-generic class
  • Generic methods in non-generic class
  • Non-generic methods in generic class
  • Generic methods in generic class
  • Non-generic methods in non-generic interface
  • Generic methods in non-generic interface
  • Non-generic methods in generic interface
  • Generic methods in generic interface

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions