func が false を返す理由は何ですか? Equals も起動しません!!!
class Program
{
static void Main(string[] args)
{
Func<Person, SomethingElse, bool> matchNested =
(p, s) => p.Nested == s.Nested;
var matched = matchNested(new Person()
{
Age = 10,
Nested = new Nested()
{
Validity = DateTime.Today
}
},
new SomethingElse()
{
Age = 10,
Nested = new Nested()
{
Validity = DateTime.Today
}
});
Console.WriteLine(matched);
}
}
internal class Person
{
public string Name { get; set; }
public int Age { get; set; }
public Nested Nested { get; set; }
}
internal class SomethingElse
{
public string Name { get; set; }
public int Age { get; set; }
public Nested Nested { get; set; }
}
internal class Nested
{
public DateTime Validity { get; set; }
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
if (!this.Validity.Equals((obj as Nested).Validity))
return false;
return base.Equals(obj);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}