我定义了一个使用 ref 对象作为参数的方法。当我尝试使用引用列表调用它时,它告诉我无法从引用列表转换为引用对象。我做了很多搜索来找到答案。然而,大多数答案是“你不需要在这里参考”或者有解决方法。
即使使用 ref (Base)[Inherited],似乎也无法从“ref [Inherited]”转换为“ref [Base]”。不知道我说得对不对。
我想要的是在 set { } 块中仅写入 1 行来更改值并发送通知。有什么建议么?
class CommonFunctions
{
public static void SetPropertyWithNotification(ref object OriginalValue, object NewValue, ...)
{
if(OriginalValue!= NewValue)
{
OriginalValue = NewValue;
//Do stuff to notify property changed
}
}
}
public class MyClass : INotifyPropertyChanged
{
private List<string> _strList = new List<string>();
public List<string> StrList
{
get { return _strList; }
set { CommonFunctions.SetPropertyWithNotification(ref _strList, value, ...);};
}
}
Run Code Online (Sandbox Code Playgroud)