{"id":1517,"date":"2019-11-16T22:56:47","date_gmt":"2019-11-16T22:56:47","guid":{"rendered":"https:\/\/docs.sisus.co\/power-inspector\/?p=1517"},"modified":"2021-03-24T17:49:22","modified_gmt":"2021-03-24T17:49:22","slug":"notnullorempty","status":"publish","type":"post","link":"https:\/\/docs.sisus.co\/power-inspector\/attributes\/notnullorempty\/","title":{"rendered":"NotNullOrEmpty"},"content":{"rendered":"<p>When added before a class member, indicates that its value can not be null or empty.<\/p>\n<p>If the value is null or empty, target will be highlighted with red color in the <a href=\"https:\/\/docs.sisus.co\/power-inspector\/terminology\/inspector-view\/\"><strong>inspector view<\/strong><\/a>.<\/p>\n<h2>Attribute Target<\/h2>\n<p>Field, property, indexer, method return value or method parameter.<br \/>\nTarget class must implement either the ICollection or IEnumerable interface in order to be validated based on being empty or not. If the current value of target does not implement neither interface, then validation will be based on only on whether or not the value is null or not.<\/p>\n<h2>Example<\/h2>\n<pre>using Sisus.Attributes;\r\nusing UnityEngine;\r\n\r\npublic class ComponentsLister : MonoBehaviour\r\n{\r\n\t[NotNullOrEmpty(Target.Collection), NotNullOrEmpty(Target.Members), ShowInInspector, ReadOnly]\r\n\tprivate string[] componentNames;\r\n\r\n\t\/\/ called when the script is loaded or a value is changed in the inspector\r\n\tvoid OnValidate() \r\n\t{\r\n\t\tUpdateComponentNames();\r\n\t}\r\n\r\n\tvoid UpdateComponentNames()\r\n\t{\r\n\t\tvar components = GetComponents&lt;Component&gt;();\r\n\t\tint count = components.Length;\r\n\t\tcomponentNames = new string[count];\r\n\t\tfor(int n = 0; n &lt; count; n++)\r\n\t\t{\r\n\t\t\tvar component = components[n];\r\n\t\t\tcomponentNames[n] = component == null ? \"\" : component.GetType().Name;\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<h2>Example Result<\/h2>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-1521\" src=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/2019\/11\/NotNullOrEmptyAttribute.png\" alt=\"\" width=\"357\" height=\"234\" srcset=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/11\/NotNullOrEmptyAttribute.png 357w, https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/11\/NotNullOrEmptyAttribute-300x197.png 300w\" sizes=\"(max-width: 357px) 100vw, 357px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When added before a class member, indicates that its value can not be null or empty. If the value is null or empty, target will be highlighted with red color in the inspector view. Attribute Target Field, property, indexer, method return value or method parameter. Target class must implement either the ICollection or IEnumerable interface ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/docs.sisus.co\/power-inspector\/attributes\/notnullorempty\/\" title=\"read more\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/1517"}],"collection":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/comments?post=1517"}],"version-history":[{"count":5,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/1517\/revisions"}],"predecessor-version":[{"id":1833,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/1517\/revisions\/1833"}],"wp:attachment":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/media?parent=1517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/categories?post=1517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/tags?post=1517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}