コード例 #1
0
        private static bool TryFormatJsonFeedAuthorObject(JsonFeedAuthor authorToFormat, out JObject authorObject)
        {
            authorObject = null;

            if (authorToFormat == null)
            {
                return(false);
            }

            if (TryFormatJsonFeedOptionalStringProperty("name", authorToFormat.Name, out var nameProperty))
            {
                // ReSharper disable once ConstantNullCoalescingCondition
                authorObject = authorObject ?? new JObject();
                authorObject.Add(nameProperty);
            }

            if (TryFormatJsonFeedOptionalStringProperty("url", authorToFormat.Url, out var urlProperty))
            {
                authorObject = authorObject ?? new JObject();
                authorObject.Add(urlProperty);
            }

            if (TryFormatJsonFeedOptionalStringProperty("avatar", authorToFormat.Avatar, out var avatarProperty))
            {
                authorObject = authorObject ?? new JObject();
                authorObject.Add(avatarProperty);
            }

            if (authorObject == null)
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
        private static bool TryFormatJsonFeedAuthorProperty(string propertyName, JsonFeedAuthor authorToFormat, out JProperty authorProperty)
        {
            authorProperty = default;

            if (!TryFormatJsonFeedAuthorObject(authorToFormat, out var authorObject))
            {
                return(false);
            }

            authorProperty = new JProperty(propertyName, authorObject);
            return(true);
        }