Skip to content

Instantly share code, notes, and snippets.

@einarwh
Created April 8, 2012 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einarwh/2340074 to your computer and use it in GitHub Desktop.
Save einarwh/2340074 to your computer and use it in GitHub Desktop.
Ensure that the type implements the INotifyPropertyChanged interface.
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