Created
October 13, 2012 04:07
-
-
Save joelmartinez/3883179 to your computer and use it in GitHub Desktop.
dynamic NSUserDefaults for MonoMac
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.Dynamic; | |
using MonoMac.Foundation; | |
namespace CodeCube | |
{ | |
public class UserSettings : DynamicObject | |
{ | |
NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults; | |
public override bool TryGetMember(GetMemberBinder binder, out object result) | |
{ | |
result = defaults.ValueForKey(new NSString(binder.Name)); | |
return result != null; | |
} | |
public override bool TrySetMember(SetMemberBinder binder, object value) | |
{ | |
defaults.SetValueForKey(NSObject.FromObject(value), new NSString(binder.Name)); | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment