Skip to content

Instantly share code, notes, and snippets.

@joelmartinez
Created October 13, 2012 04:07
Show Gist options
  • Save joelmartinez/3883179 to your computer and use it in GitHub Desktop.
Save joelmartinez/3883179 to your computer and use it in GitHub Desktop.
dynamic NSUserDefaults for MonoMac
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