The only issue I have with it is that it as to replicated across classes.
Now as I see it, if you slightly modify the code you can make it an extension method.
Different interface, so you raise the event on the correct object. (As I don't no a way to externally trigger them.).
Public Interface INotifyPropertyChanged_Extd
Inherits INotifyPropertyChanged
Sub RaisePropertyChangedEvent(ByVal source As Object, e As PropertyChangedEventArgs)
End Interface
Public Interface INotifyPropertyChanging_Extd
Inherits INotifyPropertyChanged_Extd
Sub RaisePropertyChangingEvent(ByVal source As Object, e As PropertyChangingEventArgs)
End Interface
Then you have the following extension method(s).
Imports System.Runtime.CompilerServices
Imports System.ComponentModel
Imports System.Collections.Generic
Public Module Exts
<Extension> Public Sub SetProperty(Of T, U As INotifyPropertyChanging_Extd)(ByVal obj As U,
[property] As String,
toValue As T,
ByRef usingField As T, Optional ignored As Object = Nothing)
If obj Is Nothing Then Exit Sub
If Not EqualityComparer(Of T).Default.Equals(usingField, toValue) Then
Dim old = usingField
obj.RaisePropertyChangingEvent(obj, New PropertyChangingEventArgs([property]))
usingField = toValue
obj.RaisePropertyChangedEvent(obj, New PropertyChangedEventArgs([property]))
End If
End Sub
<Extension> Public Sub SetProperty(Of T, U As INotifyPropertyChanged_Extd)(ByVal obj As U,
[property] As String,
toValue As T,
ByRef usingField As T)
If obj Is Nothing Then Exit Sub
If Not EqualityComparer(Of T).Default.Equals(usingField, toValue) Then
usingField = toValue
obj.RaisePropertyChangedEvent(obj, New PropertyChangedEventArgs([property]))
End If
End Sub
End Module
Example Class using this extension method.
Public Class Example
Implements INotifyPropertyChanged_Extd
Private _Value As Integer
Property Value As Integer
Get
Return _Value
End Get
Set(value As Integer)
Me.SetProperty("Value", value, _Value)
End Set
End Property
Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
Public Sub RaisePropertyChangedEvent(source As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged_Extd.RaisePropertyChangedEvent
RaiseEvent PropertyChanged(source, e)
End Sub
End Class
And the _PropertyChanged event being handled.
Class MainWindow
Private WithEvents MyExample As New Example
Private Sub MyExample_PropertyChanged(sender As Object, e As ComponentModel.PropertyChangedEventArgs) Handles MyExample.PropertyChanged
Debug.WriteLine(e.PropertyName)
End Sub
End Class
A found it a little misleading when you (Bob) refer to the ComplexIfStatement, kind of inferred or suggested that the Select Case decision statement can't do what the ComplexIfStatement does. (Especially with Option Strict Off)
See Example Below.
Module Module1
Sub Main()
SelectCase_Example()
Console.WriteLine()
SuperHero_Example()
Console.ReadLine()
End Sub
Public Sub SelectCase_Example()
Console.WriteLine("Select Case Example")
Dim value = 42
Select Case value
Case Is < 1, Is > 100 : Console.WriteLine("Out of bounds")
Case 23, 42, Is > 90 : Console.WriteLine("You Found one of the special numbers")
Case Else
Console.WriteLine("Not one of special numbers")
End Select
End Sub
Public Sub SuperHero_Example()
Console.WriteLine("SuperHero Example")
GreetSuperHero(11)
GreetSuperHero(SuperHeros.Batman)
End Sub
Public Sub GreetSuperHero(ByVal superhero As SuperHeros)
Dim IsMemberOfSuperHeros = [Enum].IsDefined(GetType(SuperHeros), superhero)
If IsMemberOfSuperHeros Then
Console.WriteLine("Hello: {0}", superhero.ToString)
Else
Console.WriteLine("How Are You?")
End If
End Sub
Enum SuperHeros
Superman
Batman
Spiderman
End Enum
End Module
When you use Enumerations it can be of any value that the underlying type can be.
Do the generic explicit member constraints, permit a form of generic operators? If we know the actual method used by the operator to perform the operation.
Working with Depth Data
Feb 07, 2012 at 9:00 PMWhat happens at 2000mm? Dan
Undefined behavior ?
Announcing Visual Studio Achievements Beta
Jan 19, 2012 at 7:37 AMI predict this become the Coder's Version of Farmville. (ie; must people will not two hoots, as to what achievement you've gained)
Visual Studio's will be forever tarnished, cometh the day when it is a requirement in a job vacancy.
TWC9: New Team Members, Win8, C++, SQL 2012, Cloud Numerics
Jan 13, 2012 at 10:39 PMOn the subject of INotifyPropertyChanged, the Anders Hejlsberg Way.
The only issue I have with it is that it as to replicated across classes.
Now as I see it, if you slightly modify the code you can make it an extension method.
Different interface, so you raise the event on the correct object. (As I don't no a way to externally trigger them.).
Then you have the following extension method(s).
Imports System.Runtime.CompilerServices Imports System.ComponentModel Imports System.Collections.Generic Public Module Exts <Extension> Public Sub SetProperty(Of T, U As INotifyPropertyChanging_Extd)(ByVal obj As U, [property] As String, toValue As T, ByRef usingField As T, Optional ignored As Object = Nothing) If obj Is Nothing Then Exit Sub If Not EqualityComparer(Of T).Default.Equals(usingField, toValue) Then Dim old = usingField obj.RaisePropertyChangingEvent(obj, New PropertyChangingEventArgs([property])) usingField = toValue obj.RaisePropertyChangedEvent(obj, New PropertyChangedEventArgs([property])) End If End Sub <Extension> Public Sub SetProperty(Of T, U As INotifyPropertyChanged_Extd)(ByVal obj As U, [property] As String, toValue As T, ByRef usingField As T) If obj Is Nothing Then Exit Sub If Not EqualityComparer(Of T).Default.Equals(usingField, toValue) Then usingField = toValue obj.RaisePropertyChangedEvent(obj, New PropertyChangedEventArgs([property])) End If End Sub End ModuleExample Class using this extension method.
Public Class Example Implements INotifyPropertyChanged_Extd Private _Value As Integer Property Value As Integer Get Return _Value End Get Set(value As Integer) Me.SetProperty("Value", value, _Value) End Set End Property Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged Public Sub RaisePropertyChangedEvent(source As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged_Extd.RaisePropertyChangedEvent RaiseEvent PropertyChanged(source, e) End Sub End ClassAnd the _PropertyChanged event being handled.
Class MainWindow Private WithEvents MyExample As New Example Private Sub MyExample_PropertyChanged(sender As Object, e As ComponentModel.PropertyChangedEventArgs) Handles MyExample.PropertyChanged Debug.WriteLine(e.PropertyName) End Sub End ClassBrian Beckman: Hidden Markov Models, Viterbi Algorithm, LINQ, Rx and Higgs Boson
Dec 26, 2011 at 11:37 AMWhat advantages does the MayBe monad have over an Option<T> ?
Option<T> can be thought as nullable over any "kind" of type (ref or val)
YOW! 2011: Mike Lee - The Road to Appsterdam
Dec 19, 2011 at 12:30 PMStanding Ovation & Cheers or encore! encore!.
I was like WTF!? before playing the video, by the I'm more MMM!
GoingNative 4: Jim Springfield on ATL, GoingNative Conference - Register Today!
Nov 29, 2011 at 8:01 PM++ is the postfix increment and a unary operator
So wouldn't C++11 would be a compile-time error?
Would it be more (C++)+=11?
Enumerations and the switch Decision Statement - 19
Nov 21, 2011 at 5:31 PMA found it a little misleading when you (Bob) refer to the ComplexIfStatement, kind of inferred or suggested that the Select Case decision statement can't do what the ComplexIfStatement does. (Especially with Option Strict Off)
See Example Below.
Module Module1 Sub Main() SelectCase_Example() Console.WriteLine() SuperHero_Example() Console.ReadLine() End Sub Public Sub SelectCase_Example() Console.WriteLine("Select Case Example") Dim value = 42 Select Case value Case Is < 1, Is > 100 : Console.WriteLine("Out of bounds") Case 23, 42, Is > 90 : Console.WriteLine("You Found one of the special numbers") Case Else Console.WriteLine("Not one of special numbers") End Select End Sub Public Sub SuperHero_Example() Console.WriteLine("SuperHero Example") GreetSuperHero(11) GreetSuperHero(SuperHeros.Batman) End Sub Public Sub GreetSuperHero(ByVal superhero As SuperHeros) Dim IsMemberOfSuperHeros = [Enum].IsDefined(GetType(SuperHeros), superhero) If IsMemberOfSuperHeros Then Console.WriteLine("Hello: {0}", superhero.ToString) Else Console.WriteLine("How Are You?") End If End Sub Enum SuperHeros Superman Batman Spiderman End Enum End ModuleWhen you use Enumerations it can be of any value that the underlying type can be.
See Example Code above
TWC9: VS11, HTML5, Debugging, and guest host Habib Heydarian
Nov 12, 2011 at 10:16 PMIs this the Charles Torres Tribute Edition? ~40 minutes!
Ping 122: Omnitouch, PocketTouch, Cutting Phone Costs, Ballmer's Feeling Lucky
Oct 25, 2011 at 2:10 PMMaybe Laura's fate should involving nakedness ( god no, in all that is holy no. ) and a plackard saying "Lost To Paul" in Pike Street Market.
Or Laura having to put Paul face as the Background and or lock screen on her phone.
Tao Liu: F# Design Patterns
Oct 19, 2011 at 4:33 AMDo the generic explicit member constraints, permit a form of generic operators? If we know the actual method used by the operator to perform the operation.
See more comments…