Esempio n. 1
0
            public object ReadJson(ref JReader reader)
            {
                var obj = reader.ObjectOrNull().WithRequiredProperties(_requiredProperties);

                if (!obj.IsDefined)
                {
                    return(null);
                }
                var builder = User.Builder("");

                try
                {
                    while (obj.Next(ref reader))
                    {
                        switch (obj.Name.ToString())
                        {
                        case "key":
                            builder.Key(reader.String());
                            break;

                        case "secondary":
                            builder.Secondary(reader.StringOrNull());
                            break;

                        case "ip":
                            builder.IPAddress(reader.StringOrNull());
                            break;

                        case "country":
                            builder.Country(reader.StringOrNull());
                            break;

                        case "firstName":
                            builder.FirstName(reader.StringOrNull());
                            break;

                        case "lastName":
                            builder.LastName(reader.StringOrNull());
                            break;

                        case "name":
                            builder.Name(reader.StringOrNull());
                            break;

                        case "avatar":
                            builder.Avatar(reader.StringOrNull());
                            break;

                        case "email":
                            builder.Email(reader.StringOrNull());
                            break;

                        case "anonymous":
                            builder.AnonymousOptional(reader.BoolOrNull());
                            break;

                        case "custom":
                            for (var customObj = reader.ObjectOrNull(); customObj.Next(ref reader);)
                            {
                                builder.Custom(customObj.Name.ToString(),
                                               LdValueConverter.ReadJsonValue(ref reader));
                            }
                            break;

                        case "privateAttributeNames":
                            var internalBuilder = builder as UserBuilder;
                            for (var arr = reader.ArrayOrNull(); arr.Next(ref reader);)
                            {
                                internalBuilder.AddPrivateAttribute(reader.String());
                            }
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    throw reader.TranslateException(e);
                }
                return(builder.Build());
            }