C#反射无参数get方法

问题描述 投票:0回答:1

我有这个代码:

MethodInfo method = typeof(AppDbContext)
     .GetMethod(nameof(AppDbContext.Set), BindingFlags.Public | BindingFlags.Instance);

DbContext
Set<>()
Set<>(string name)
中有两个名为Set的方法,问题是,这段代码存在歧义。 那么如何获取不带参数的方法呢?

c# reflection entity-framework-core
1个回答
0
投票

您需要使用 .GetMethod() 的重载,其中有一个 Type[] 类型的数组,并向其传递一个长度为 0 的数组。

© www.soinside.com 2019 - 2024. All rights reserved.