{"id":3896,"date":"2020-08-12T11:32:46","date_gmt":"2020-08-12T10:32:46","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=3896"},"modified":"2020-08-12T11:32:46","modified_gmt":"2020-08-12T10:32:46","slug":"add-only-non-null-xelements","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/add-only-non-null-xelements\/","title":{"rendered":"Add only non null XElements"},"content":{"rendered":"\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public IEnumerable&lt;XElement> GetElements(string[,] parameters)\n{\n\tfor (int i = 0; i &lt; parameters.GetLength(0); i += 1)\n\t{\n\t\tvar key = parameters[i, 0];\n\t\tvar value = parameters[i, 1];\n\t\tif (string.IsNullOrEmpty(value))\n\t\t\tcontinue;\n\t\tyield return new XElement(key, new XText(value));\n\t}\n}\n\/\/ usage:\nvar message = new XElement(\"Message\",\n\t\tGetElements(new string[,] {\n\t\t\t{ \"Title\", \"The title\" },\n\t\t\t{ \"Content\", \"The content\" }\n\t\t\t{ \"NotIncluded\", null }\n\t\t})\n\t);<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3896","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=3896"}],"version-history":[{"count":1,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3896\/revisions"}],"predecessor-version":[{"id":3897,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/3896\/revisions\/3897"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=3896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=3896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=3896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}