Пример #1
0
        private static MPTweak LoadOrCreateMixpanelTweak(MPTweakStore store, Tweak tweak)
        {
            var mpTweak = store.TweakWithName(tweak.Name);

            if (mpTweak != null)
            {
                return(mpTweak);
            }

            mpTweak = CreateMixpanelTweak(tweak);
            store.AddTweak(mpTweak);
            return(mpTweak);
        }
Пример #2
0
        private static MPTweak CreateMixpanelTweak(Tweak tweak)
        {
            var tweakType = tweak.GetType();
            var valueType = tweakType.GetGenericArguments()[0];

            MPTweak mpTweak;

            if (valueType == typeof(int))
            {
                mpTweak = new MPTweak(tweak.Name, "i");
                mpTweak.DefaultValue = NSNumber.FromInt32((int)tweak.DefaultValue);
                if (tweak.Min != null)
                {
                    mpTweak.MinimumValue = NSNumber.FromInt32((int)tweak.Min);
                }
                if (tweak.Max != null)
                {
                    mpTweak.MaximumValue = NSNumber.FromInt32((int)tweak.Max);
                }
            }
            else if (valueType == typeof(float))
            {
                mpTweak = new MPTweak(tweak.Name, "f");
                mpTweak.DefaultValue = NSNumber.FromFloat((float)tweak.DefaultValue);
                if (tweak.Min != null)
                {
                    mpTweak.MinimumValue = NSNumber.FromFloat((float)tweak.Min);
                }
                if (tweak.Max != null)
                {
                    mpTweak.MaximumValue = NSNumber.FromFloat((float)tweak.Max);
                }
            }
            else if (valueType == typeof(bool))
            {
                mpTweak = new MPTweak(tweak.Name, "c");
                mpTweak.DefaultValue = NSNumber.FromBoolean((bool)tweak.DefaultValue);
            }
            else if (valueType == typeof(string))
            {
                mpTweak = new MPTweak(tweak.Name, "@");
                mpTweak.DefaultValue = new NSString((string)tweak.DefaultValue);
            }
            else
            {
                throw new InvalidOperationException($"Type {valueType} is not supported as a tweak value type. Supported types: bool, int, float, string.");
            }
            return(mpTweak);
        }
Пример #3
0
 public TweakObserver(Tweak <TValue> tweak)
 {
     _tweak = tweak;
 }