Comments (16)
This is by design. I must call Type typeOf = value.GetType(); to get the type of the value so if value is null it will throw an exception and there isn't too much I could do about it at that point. Additionally, I could not guarantee the underlying settings method allows null values on all platforms.
from xamarin.plugins.
Actually I was thinking about removing record if value is null. Cause at the moment I have to use "special values" to "remove" record.
from xamarin.plugins.
Ahhhh interesting. I might be able to introduce a remove into the API. Let me see what I can do
from xamarin.plugins.
So a question @halkar would be can't you just set it back to the default value and check against that? Adding a remove method would simply mean that next time you get the value back it would be the default anyways.
Also are you storing strings? That would be the only nullable type in there....
from xamarin.plugins.
@jamesmontemagno in my case it was nullable DateTime. So yes, I'm using special value for now, but being able to check value against null instead of DateTime.MinValue will be a plus ;) And doesn't matter how it would be implemented as "Remove" method or by setting null as a value.
from xamarin.plugins.
Actually I'm ok to implement that by myself if you agree that it will be useful.
from xamarin.plugins.
@halkar how everything is implemented it would get the default value of Null next time you asked for it which would most likely be DateTime.MinValue. All of them are stored as a long though in the settings.
I am just a bit confused about why you need to remove a value.
The issue here is that when I first released this plugin a long time ago the API was probably a bit wrong:
bool AddOrUpdateValue(string key, Object value);
this is the current method, and I need to get the type of value to then set it correctly. If it is null then I can't figure out how to store your setting so it throws an exception, which is how I designed it originally. If you think about it it makes sense.
Ideally though I could have originally made it:
bool AddOrUpdateValue(string key, T value = default(T));
This probably would have been the better way of doing it, but a bit late right now.
The real debate that I can solve it in 1 of 3 ways:
1.) Add a remove method for a key (however next time you call GetValueOrDefault it will return your default
2.) If you set value to null then automatically remove the key (however next time you call getvalueordefault it will return the default)
3.) Leave it as is.
from xamarin.plugins.
@jamesmontemagno I'm confused now too %)
First default(DateTime?) == null and I'd like to check if value is null and not DateTime.MinValue.
Second both 1 and 2 approaches are good for me but 1 is more straightforward, obvious and less risky.
If you don't like the idea - that's ok. No pressure ;)
from xamarin.plugins.
I don't believe that the API will actually support DateTime? and in fact I do Convert.ToDateTime(value) and that would be DateTime.MinValue.
The other issue is that when I call:
var defaults = NSUserDefaults.StandardUserDefaults;
defaults.ValueForKey(new NSString(key));
This method on iOS ValueForKey will return null if the value doesn't exists. So you can't really save null....
from xamarin.plugins.
So I think that might work if you set the default to null to begin, which means that it will return null as the default. Now once you set it you could try to set it to null, but that will result in a DateTime.Min. However, you could remove the key, and then if you call Get it will return null.
Odd edgecase, but crafting some things. Need to ensure I don't break apps and that I like that API if I change it.
from xamarin.plugins.
Sure. I'm trying to implement that at the moment by myself. Thank you!
from xamarin.plugins.
@halkar so if you pull down this branch and test it you will see my changes to the API:
https://github.com/jamesmontemagno/Xamarin.Plugins/tree/settings_remove_option
I still need to do testing and put the API under review.
from xamarin.plugins.
@jamesmontemagno looks good!
from xamarin.plugins.
I have released this as an alpha: https://www.nuget.org/packages/Xam.Plugins.Settings/2.0.0-alpha
Please test and let me know
from xamarin.plugins.
Tested, everything is fine with me. Thank you!
from xamarin.plugins.
1.5.0 is official now
from xamarin.plugins.
Related Issues (20)
- IsRemoteReachable always fails on an IPv4 network, however IPv6 is ok (iOS) HOT 1
- PermissionStatus.Unknown HOT 1
- Add better null handling to contact loading. HOT 1
- Question - Media plugin HOT 1
- Permission Request Description required in iOS 10. HOT 1
- TapGestureRecognizer Command is not getting raised after imagecircle.IsEnabled changes HOT 3
- GeoLocator, Battery and Contacts cannot be built for Release, Debug build has no issues HOT 2
- System.MissingMethodException Method Android.GMS.Maps.MapView.get_Map Not Found HOT 2
- Geolocator conflicts with Xamarin.GooglePlayServices.Ads
- Camera app crashes when trying to playback video before saving in Android 7 HOT 1
- crash app oh ur map
- Restarting the app while taking photo and after clicking OK HOT 1
- Tizen support please :-) HOT 1
- Readme broken link HOT 1
- How to check whether it is Mobile data or Wifi?
- CrosscurrentActivity for iOs HOT 2
- Permissions not working properly HOT 1
- Image display rotated in web which is taken by IPhone HOT 1
- Shared transitions HOT 2
- MacOS Support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xamarin.plugins.