Reflection TargetException:对象与目标类型不匹配

Reflection TargetException:对象与目标类型不匹配,reflection,reflection.emit,Reflection,Reflection.emit,当我尝试此代码时,我遇到此wierd错误: class SomeClass { public decimal ClientCode { get; set; } public DateTime Date { get; set; } public override int GetHashCode() { int sum = 0; foreach (var p in GetType().GetProperties())

当我尝试此代码时,我遇到此wierd错误:

class SomeClass
{
    public decimal ClientCode { get; set; }
    public DateTime Date { get; set; }

    public override int GetHashCode()
    {
        int sum = 0;
        foreach (var p in GetType().GetProperties())
        {
            var method = p.GetType().GetMethod("GetHashCode");
            var value = p.GetValue(this, null);
            sum += (int)(method.Invoke(value, null)); //  <-- HERE!
        }

        return sum;
    }
}
class-SomeClass
{
公共十进制客户端代码{get;set;}
公共日期时间日期{get;set;}
公共覆盖int GetHashCode()
{
整数和=0;
foreach(GetType().GetProperties()中的var p)
{
var method=p.GetType().GetMethod(“GetHashCode”);
var value=p.GetValue(此值为空);

sum+=(int)(method.Invoke(value,null));//我必须从对象而不是从PropertyType获取GetHashCode

public class SomeClass
{
    public decimal ClientCode { get; set; }
    public DateTime Date { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
    public byte B { get; set; }

    public override int GetHashCode()
    {
        int sum = 0;
        foreach (var p in GetType().GetProperties())
        {
            var method = typeof(object).GetMethod("GetHashCode");
            var value = p.GetValue(this, null);
            if (value != null)
                sum += (int)(method.Invoke(value, null));
        }

        return sum;
    }
}