English 中文(简体)
不动产类型和性质
原标题:Nullable Types and properties with INotifyPropertyChanged

似乎过高地确定一种无效的类型的价值,并实行冻结。 是否有更好的办法这样做?

        Private _WorkPhone As Long?
    Public Property [WorkPhone]() As Long?
        Get
            Return _WorkPhone
        End Get
        Set(ByVal value As Long?)
            If value.HasValue = False Then
                If _WorkPhone.HasValue = True Then
                    MyBase.RaisePropertyChanging("WorkPhone")
                    _WorkPhone = Nothing
                    MyBase.MarkDirty()
                    MyBase.RaisePropertyChanged("WorkPhone")
                End If
            Else
                If _WorkPhone.HasValue Then
                    If _WorkPhone.Value <> value.Value Then
                        MyBase.RaisePropertyChanging("WorkPhone")
                        _WorkPhone = value
                        MyBase.MarkDirty()
                        MyBase.RaisePropertyChanged("WorkPhone")
                    End If
                Else
                    MyBase.RaisePropertyChanging("WorkPhone")
                    _WorkPhone = value
                    MyBase.MarkDirty()
                End If
                MyBase.RaisePropertyChanged("WorkPhone")
            End If
        End Set
    End Property

我尝试使用简单的法典,但我在上的休息点。 MyBase.RaisePropertyChanging(“WorkPhone”)从未受到过任何打击,其价值从未发生变化。

    If _WorkPhone <> value Then
    MyBase.RaisePropertyChanging("WorkPhone")
    _WorkPhone = value
    MyBase.MarkDirty()
    MyBase.RaisePropertyChanged("WorkPhone")
End If
最佳回答

没有必要所有复杂的逻辑。 如果并且只在下述情况下,<代码>x和y均为无效,其基础相同:x等于

  1. x.HasValue is true
  2. y.HasValue is true
  3. x.Value equals y.Value

  1. x.HasValue is false
  2. y.HasValue is false

In neither of these cases would we want to raise a property changed notification and thus a simple test f或 non-equality will suffice. Thus:

Private _W或kPhone As Long?
    Public Property [W或kPhone]() As Long?
        Get
            Return _W或kPhone
        End Get
        Set(ByVal value As Long?)
            If Not _w或kPhone.Equals(value)
                MyBase.RaisePropertyChanging("W或kPhone")
                _W或kPhone = value
                MyBase.MarkDirty()
                MyBase.RaisePropertyChanged("W或kPhone")
            EndIf
        End Set
    End Property

请注意,如果其歌剧为Not Nullable (Of T.Equals 而不是<>,作为后者评价Nothing ,则我们应使用。

问题回答

页: 1 我注意到你正在利用LONG储存工作电话号码。 即便没有签名,这也会在美国的429号区域代码上失败。 您可考虑代议或战略





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签