-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels