Created
December 9, 2014 18:07
-
-
Save ironpythonbot/f6f92e417f6e275fb2eb to your computer and use it in GitHub Desktop.
CodePlex Issue #33838 Plain Text Attachments
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
csharp = ''' | |
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Dynamic; | |
using System.Linq; | |
namespace TrySetMember { | |
public class MyDynamicObject : DynamicObject, INotifyPropertyChanged { | |
protected internal IDictionary<string, object> itemDictionary = new Dictionary<string, object>(); | |
public event PropertyChangedEventHandler PropertyChanged; | |
protected virtual void OnPropertyChanged(string propertyName) { | |
if (PropertyChanged != null) { | |
PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} | |
public sealed override bool TrySetMember(SetMemberBinder binder, object value) { | |
Console.WriteLine("TrySetMember " + binder.Name); | |
itemDictionary[binder.Name] = value; | |
OnPropertyChanged(binder.Name); | |
return true; | |
} | |
} | |
} | |
''' | |
import clr | |
from System.ComponentModel import PropertyChangedEventHandler | |
from System.IO import File | |
from System.Diagnostics import Process | |
File.WriteAllText("MyDynamicObject.cs", csharp) | |
compiler = Process(); | |
compiler.StartInfo.FileName = "csc.exe"; | |
compiler.StartInfo.Arguments = "/target:library MyDynamicObject.cs"; | |
compiler.StartInfo.UseShellExecute = True; | |
compiler.Start() | |
clr.AddReference('MyDynamicObject') | |
from TrySetMember import MyDynamicObject | |
def myHandler(sender, args): | |
print 'Property changed {0}'.format(args.PropertyName) | |
container = MyDynamicObject() | |
container.PropertyChanged += myHandler | |
print 'Done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment