Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,6 @@ public override bool IsAssignableFrom([NotNullWhen(true)] Type? c)
string name, BindingFlags bindingFlags, Binder? binder, object? target,
object?[]? providedArgs, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParams)
{
ArgumentNullException.ThrowIfNull(name);

const BindingFlags MemberBindingMask = (BindingFlags)0x000000FF;
const BindingFlags InvocationMask = (BindingFlags)0x0000FF00;
const BindingFlags BinderGetSetField = BindingFlags.GetField | BindingFlags.SetField;
Expand Down Expand Up @@ -567,10 +565,12 @@ public override bool IsAssignableFrom([NotNullWhen(true)] Type? c)
// PutDispProperty and\or PutRefDispProperty ==> SetProperty.
if ((bindingFlags & (BindingFlags.PutDispProperty | BindingFlags.PutRefDispProperty)) != 0)
bindingFlags |= BindingFlags.SetProperty;

ArgumentNullException.ThrowIfNull(name);
if (name.Length == 0 || name.Equals("[DISPID=0]"))
{
// in InvokeMember we always pretend there is a default member if none is provided and we make it ToString
name = GetDefaultMemberName()! ?? "ToString";
name = GetDefaultMemberName() ?? "ToString";
}

// GetField or SetField
Expand Down
8 changes: 8 additions & 0 deletions src/libraries/System.Reflection/tests/DefaultBinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ public static void InvokeWithNamedParametersOutOfOrder()
Assert.Equal(8, result);
}

[Theory]
[InlineData("")]
[InlineData(null)]
public static void InvokeWithCreateInstance(string name)
{
Assert.IsType<Sample>(typeof(Sample).InvokeMember(name, BindingFlags.CreateInstance, null, null, null));
}

public class Test
{
public void TestMethod(int param1) { }
Expand Down