我在具有属性的类中有一个类,例如 Car.Engine.Name。我已经实现了 KVC,并想为“Engine.Name”发送 WillChangeValue,但它似乎没有注册。另一方面,为 Car.Name 发送“名称”的 WillChangeValue 确实有效。
Object target = _t;
PropertyInfo info;
for (int i = 0; i < keys.Length; i++) {
info = target.GetType ().GetProperty (keys[i]);
if (i == keys.Length - 1) {
WillChangeValue (nsKeyPath); // <--- doesn't seem to work if there is a nontrival keypath
info.SetValue (target, nsValue.ToObject (info.PropertyType), null);
DidChangeValue (nsKeyPath);
} else {
target = info.GetValue (target, null);
}
}