GetProperty reflection results in “Ambiguous match found” on new property

前端 未结 7 1166
离开以前
离开以前 2020-12-30 19:25

How can I get my property? Currently an error is occuring of Ambiguous match found, see the comment line in code.

public class MyBaseEntity
{
           


        
7条回答
  •  春和景丽
    2020-12-30 20:07

    For property:

    MemberInfo property = myDE.GetProperty(
        "MyEntity",
        BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
    

    For method:

    MemberInfo method = typeof(String).GetMethod(
        "ToString",
        BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly,
        null,
        new Type[] { },// Method ToString() without parameters
        null);
    

    BindingFlags.DeclaredOnly - Specifies that only members declared at the level of the supplied type's hierarchy should be considered. Inherited members are not considered.

提交回复
热议问题