internal WebpushNotification CopyAndValidate()

in FirebaseAdmin/FirebaseAdmin/Messaging/WebpushNotification.cs [178:219]


        internal WebpushNotification CopyAndValidate()
        {
            var copy = new WebpushNotification()
            {
                Title = this.Title,
                Body = this.Body,
                Icon = this.Icon,
                Image = this.Image,
                Language = this.Language,
                Tag = this.Tag,
                Direction = this.Direction,
                Badge = this.Badge,
                Renotify = this.Renotify,
                RequireInteraction = this.RequireInteraction,
                Silent = this.Silent,
                Actions = this.Actions?.Select((item, _) => new Action(item)).ToList(),
                Vibrate = this.Vibrate,
                TimestampMillis = this.TimestampMillis,
                Data = this.Data,
            };

            var customData = this.CustomData?.ToDictionary(e => e.Key, e => e.Value);
            if (customData?.Count > 0)
            {
                var serializer = NewtonsoftJsonSerializer.Instance;
                var json = serializer.Serialize(copy);
                var standardProperties = serializer.Deserialize<Dictionary<string, object>>(json);
                var duplicates = customData.Keys
                    .Where(customKey => standardProperties.ContainsKey(customKey))
                    .ToList();
                if (duplicates.Any())
                {
                    throw new ArgumentException(
                        "Multiple specifications for WebpushNotification keys: "
                        + string.Join(",", duplicates));
                }

                copy.CustomData = customData;
            }

            return copy;
        }