Last active
August 29, 2015 14:12
-
-
Save emoacht/b3fc16f6584c79164552 to your computer and use it in GitHub Desktop.
CallerMemberNameAttribute for .NET Framework earlier than 4.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System.Runtime.CompilerServices | |
{ | |
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] | |
public class CallerMemberNameAttribute : Attribute | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Namespace Global.System.Runtime.CompilerServices | |
<AttributeUsage(AttributeTargets.Parameter, AllowMultiple:=False, Inherited:=False)> | |
Public Class CallerMemberNameAttribute | |
Inherits Attribute | |
End Class | |
End Namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.ComponentModel; | |
using System.Runtime.CompilerServices; | |
public abstract class NotificationObject : INotifyPropertyChanged | |
{ | |
public event PropertyChangedEventHandler PropertyChanged; | |
protected virtual void RaisePropertyChanged(ISynchronizeInvoke invoker, [CallerMemberName] string propertyName = null) | |
{ | |
if ((invoker != null) && invoker.InvokeRequired) | |
{ | |
invoker.Invoke(new Action(() => RaisePropertyChanged(propertyName)), null); | |
} | |
else | |
{ | |
RaisePropertyChanged(propertyName); | |
} | |
} | |
protected virtual void RaisePropertyChanged([CallerMemberName] string propertyName = null) | |
{ | |
var handler = PropertyChanged; | |
if (handler != null) | |
{ | |
handler(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.ComponentModel | |
Imports System.Runtime.CompilerServices | |
Public MustInherit Class NotificationObject | |
Implements INotifyPropertyChanged | |
Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged | |
Protected Overridable Sub RaisePropertyChanged(invoker As ISynchronizeInvoke, <CallerMemberName> Optional propertyName As String = Nothing) | |
If ((invoker IsNot Nothing) AndAlso invoker.InvokeRequired) Then | |
invoker.Invoke(Sub() RaisePropertyChanged(propertyName), Nothing) | |
Else | |
RaisePropertyChanged(propertyName) | |
End If | |
End Sub | |
Protected Overridable Sub RaisePropertyChanged(<CallerMemberName> Optional propertyName As String = Nothing) | |
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName)) | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment