예제 #1
0
        internal static SegmentRule ReadSegmentRule(ref JReader reader)
        {
            ImmutableList <Clause> clauses = null;
            int?          weight           = null;
            UserAttribute?bucketBy         = null;

            for (var obj = reader.Object(); obj.Next(ref reader);)
            {
                switch (obj.Name)
                {
                case var n when n == "clauses":
                    clauses = SerializationHelpers.ReadClauses(ref reader);
                    break;

                case var n when n == "weight":
                    weight = reader.IntOrNull();
                    break;

                case var n when n == "bucketBy":
                    var s = reader.StringOrNull();
                    bucketBy = s is null ? (UserAttribute?)null : UserAttribute.ForName(s);
                    break;
                }
            }
            return(new SegmentRule(clauses, weight, bucketBy));
        }
예제 #2
0
        internal static FlagRule ReadFlagRule(ref JReader r)
        {
            string  id        = null;
            int?    variation = null;
            Rollout?rollout   = null;
            ImmutableList <Clause> clauses = null;
            bool trackEvents = false;

            for (var obj = r.Object(); obj.Next(ref r);)
            {
                switch (obj.Name)
                {
                case var n when n == "id":
                    id = r.StringOrNull();
                    break;

                case var n when n == "variation":
                    variation = r.IntOrNull();
                    break;

                case var n when n == "rollout":
                    rollout = ReadRollout(ref r);
                    break;

                case var n when n == "clauses":
                    clauses = SerializationHelpers.ReadClauses(ref r);
                    break;

                case var n when n == "trackEvents":
                    trackEvents = r.Bool();
                    break;
                }
            }
            return(new FlagRule(variation, rollout, id, clauses, trackEvents));
        }