Skip to content

Incorrect binder.ReturnType #40

@nesteruk

Description

@nesteruk

Say we define a null object like this:

  public class Null<T> : DynamicObject where T:class
  {
    public static T Instance
    {
      get
      {
        if (!typeof(T).IsInterface)
          throw new ArgumentException("I must be an interface type");
    
        return new Null<T>().ActLike<T>();
      }
    }
  
    public override bool TryInvokeMember(InvokeMemberBinder binder, 
      object[] args, out object result)
    {
      result = Activator.CreateInstance(binder.ReturnType);
      return true;
    }
  }

And an interface like this

public interface ILog
{
  void Info(string msg);
  bool Warn(string msg);
}

Calling Null<ILog>.Instance.Warn("...") gives an exception because in TryInvokeMember, the value of binder.ReturnType is System.Object for some reason. Looks like ImpromptuInterface is failing to specify binder.ReturnType correctly on the basis of what the members actually are. binder.Name is correct, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions