jamesmontemagno / SettingsPlugin

Read and Write Settings Plugin for Xamarin and Windows
MIT License
324 stars 80 forks source link

enum #119

Closed tofutim closed 6 years ago

tofutim commented 6 years ago

Interested in adding enums? I've been using this.

      public static TEnum GetEnumValueOrDefault<TEnum>(this ISettings settings, TEnum defaultValue, string fileName = null)
            where TEnum : struct
        {
            TEnum result = default(TEnum);
            bool enumParseResult = false;

            var strTarget = settings.GetValueOrDefault(nameof(TEnum), defaultValue.ToString(), fileName);
            enumParseResult = Enum.TryParse(strTarget, true, out result);
            return result;
        }

        public static bool AddOrUpdateEnumValue<TEnum>(this ISettings settings, TEnum value, string fileName = null)
        {
            return settings.AddOrUpdateValue(nameof(TEnum), value.ToString(), fileName);
        }
jamesmontemagno commented 6 years ago

Each platform does not handle Enums. You can parse to Int and save that or yourself. The plugin will not handle this.