Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

索引器重载时属性的GetMethod和SetMethod不正确 #672

Merged
merged 2 commits into from
Mar 18, 2022

Conversation

Endures
Copy link
Contributor

@Endures Endures commented Mar 16, 2022

如下热更代码定义了2个重载的索引器

public class TestCls
{
    [System.Runtime.CompilerServices.IndexerName("Ccc")]
    public bool this[int i]
    {
        get { return true; }
    }

    [System.Runtime.CompilerServices.IndexerName("Ccc")]
    public bool this[string s]
    {
        get { return false; }
    }
}

那么这2个索引器属性的GetMethod和SetMethod全部为整形参数索引器的GetMethod和SetMethod。原因为源码中只使用方法名称获取getter和setter

if (pd.GetMethod != null)
pi.Getter = type.GetMethod(pd.GetMethod.Name, pd.GetMethod.Parameters.Count) as ILMethod;
if (pd.SetMethod != null)
pi.Setter = type.GetMethod(pd.SetMethod.Name, pd.SetMethod.Parameters.Count) as ILMethod;

将这部分代码修改为使用方法名称和参数类型去匹配

if (pd.GetMethod != null)
{
    pi.Getter = type.GetMethod(pd.GetMethod.Name, pd.GetMethod.Parameters.Select(p => type.AppDomain.GetType(p.ParameterType, null, null)).ToList(), null) as ILMethod;
}
if (pd.SetMethod != null)
{
    pi.Setter = type.GetMethod(pd.SetMethod.Name, pd.SetMethod.Parameters.Select(p => type.AppDomain.GetType(p.ParameterType, null, null)).ToList(), null) as ILMethod;
}

已增加测试用例TestCases.ReflectionTest.TestPropertyIndexParametersInfo与TestCases.ReflectionTest.TestMethodParametersInfo

@liiir1985 liiir1985 merged commit 4939837 into Ourpalm:master Mar 18, 2022
@Endures Endures deleted the ParameterInfo branch March 21, 2022 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants