MVVM Light Toolkit 4.5 Set 方法

4

刚刚注意到4.2.30版本没有包含

protected bool Set<T>(
            ref T field,
            T newValue,
            [CallerMemberName] string propertyName = null)
        {
            return Set(propertyName, ref field, newValue);
        }

由于编译常量“CMNATTR”在发布模式下未作为构建参数定义。 不知道这是错误还是故意的? 谢谢。
1个回答

2
我今天刚碰到这个问题,我也想在MVVMLight提供的一些方法中使用[CallerMemberName]。Laurent之前在讨论中回答了该问题,但似乎他还没有时间来修复这个问题。因此,一种选择是下载源代码,设置符号并在发布模式下重新构建。我自己还没有尝试过,也不确定这是否会产生其他影响。
现在的另一个解决方法是扩展ViewModelBase并添加需要的方法变体,带有[CallerMemberName]。例如,在您的情况下:
public class ViewModelBaseCustom : ViewModelBase
{
    public bool Set<T>(ref T field, T value, [CallerMemberName] string propertyName = "")
    {
        return this.Set(propertyName, ref field, value);
    }
}

然后在MVVMLight更新之前,使用这个Laurent原版的自定义版本。


我所做的就是使用CMNATTR编译。到目前为止,它运行得非常好。 - Tech Wizard
Laurent刚刚在Build上发表评论,称下周即将推出新版本,其中包括此功能/修复。来源:https://mvvmlight.codeplex.com/discussions/492941 - Thomas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接