Created
April 8, 2012 22:13
-
-
Save einarwh/2340074 to your computer and use it in GitHub Desktop.
Ensure that the type implements the INotifyPropertyChanged interface.
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
private bool ReallyTamperWith() | |
{ | |
EnsureTypeImplementsInterface(); | |
TamperWithPropertySetters(); | |
return true; | |
} | |
private void EnsureTypeImplementsInterface() | |
{ | |
if (!TypeAlreadyImplementsInterface()) | |
{ | |
InjectInterfaceImplementation(); | |
} | |
IdentifyNotificationMethod(); | |
} | |
private static bool TypeImplementsInterface(TypeDefinition typeDef) | |
{ | |
return | |
typeDef.Interfaces.Any( | |
it => it.Name == "INotifyPropertyChanged") | |
|| | |
(typeDef.BaseType != null | |
&& TypeImplementsInterface(typeDef.BaseType.Resolve())); | |
} | |
private void InjectInterfaceImplementation() | |
{ | |
InjectInterfaceDeclaration(); | |
InjectEventHandler(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment