Home
Do you always create suggestions when something is hard to do?
  v1.0 Posted at 1/05/2018 8:07 AM by Tiago Araujo

One of our goals is to make the job of the developer as easy as possible. If you have to write a lot of code for something that you think you should not have to do, you should make a suggestion and add it to the relevant page.

If you have to add a suggestion, make sure that you put the link to that suggestion into the comments of your code.​​

​Imports System.Windows.Threading
Imports System.Threading
''' <summary>
''' base class for command implementations
''' This is a work around as standard MVVM commands
''' are not provided by default
''' </summary>
''' <remarks></remarks>
Public MustInherit Class Command
Implements ICommand
Private m_dispatcher As Dispatcher
Protected Sub New()
If Not Application.Current Is Nothing Then
m_dispatcher = Application.Current.Dispatcher
Else
m_dispatcher = Dispatcher.CurrentDispatcher
End If
Debug.Assert(Not m_dispatcher Is Nothing)
End Sub
Public MustOverride Function CanExecute(ByVal parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute
Public MustOverride Sub Execute(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute
Public Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements System.Windows.Input.ICommand.CanExecuteChanged

Public Sub OnCanExecuteChanged()
If Not m_dispatcher.CheckAccess Then
m_dispatcher.Invoke(New ThreadStart(AddressOf OnCanExecuteChanged), DispatcherPriority.Normal)
Else
CommandManager.InvalidateRequerySuggested()
RaiseEvent CanExecuteChanged(Me, New EventArgs)
End If
End Sub
End Class

Figure: Bad example - The link to the suggestion should be in the comments​

​Imports System.Windows.Threading
Imports System.Threading
''' <summary>
''' base class for command implementations
''' This is a work around as standard MVVM commands
''' are not provided by default
''' http://www.ssw.com.au/ssw/Standards/BetterSoftwareSuggestions/WPF.aspx#EmbraseMVVM
''' </summary>
''' <remarks></remarks>
Public MustInherit Class Command
Implements ICommand
Private m_dispatcher As Dispatcher
Protected Sub New()
If Not Application.Current Is Nothing Then
m_dispatcher = Application.Current.Dispatcher
Else
m_dispatcher = Dispatcher.CurrentDispatcher
End If
Debug.Assert(Not m_dispatcher Is Nothing)
End Sub
Public MustOverride Function CanExecute(ByVal parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute
Public MustOverride Sub Execute(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute
Public Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements System.Windows.Input.ICommand.CanExecuteChanged

Public Sub OnCanExecuteChanged()
If Not m_dispatcher.CheckAccess Then
m_dispatcher.Invoke(New ThreadStart(AddressOf OnCanExecuteChanged), DispatcherPriority.Normal)
Else
CommandManager.InvalidateRequerySuggested()
RaiseEvent CanExecuteChanged(Me, New EventArgs)
End If
End Sub
End Class

​Figure: Good example - Wh​​en you link to a suggestion everyone can find it and vote it up


Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments:

    Note: Social Media login for Yotpo is not working in IE or Safari, please use Chrome. We are waiting for Yotpo to fix it.