开发者

NSUserDefaults in monotouch

开发者 https://www.devze.com 2022-12-25 23:18 出处:网络
I\'m very impressed with MonoTouch.Dialog by Miguel. inspired by his simple approach I thought it would be very nice to have a reflection based NSUserDefaults class that works seamlessly by marking ce

I'm very impressed with MonoTouch.Dialog by Miguel. inspired by his simple approach I thought it would be very nice to have a reflection based NSUserDefaults class that works seamlessly by marking certain properties as "persistable in user defaults" and forget about the rest. something like this:

    public class SomeController
    {
        [PersistInUserSettings]
        public string LastPostUserRead { get; set; }
    }

I don't like the LastPostUserRead to be of type "UserSetting", I like it to be a normal property so that later I can assign to it like:

LastPostUserRead = "Post 1";

and not like:

LastPostUserRead.SetValue("Post 1");

Any idea on h开发者_StackOverflowow to implement it (without Reflection.Emit) in monotouch?


You do not need Reflection.Emit at all to dynamically set values. That is pure System.Reflection (without the "Emit" part).

MonoTouch.Dialog in fact reads and stores values dynamically using SetValue and GetValue from the FieldInfo (could be done for properties too).

0

精彩评论

暂无评论...
验证码 换一张
取 消