{"id":1087,"date":"2021-02-19T08:59:00","date_gmt":"2021-02-19T15:59:00","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=1087"},"modified":"2021-02-15T09:17:20","modified_gmt":"2021-02-15T16:17:20","slug":"operator_lookup","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2021\/02\/19\/operator_lookup\/","title":{"rendered":"Operator_Lookup"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In code I&#8217;ve been writing I&#8217;ve found a need to be able to &#8220;add properties&#8221; &#8211; but not in a conventional way. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Normally I&#8217;d just add a property to some class in my Xojo code and be off &amp; running. But now I&#8217;m needing to be able to define &#8220;classes&#8221; (They&#8217;re not really classes) in a way that they can be added EVEN AFTER the application has been compiled.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So this means I need to be able to added to a text file, that gets read, and a new &#8220;property&#8221; is available on the &#8220;class&#8221;. Admittedly a very unusual need.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But this IS possible.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There is a little used method that any class can use to make it so the compiler can &#8220;lookup&#8221; something that is not defined in the conventional ways. That method is _operator_lookup_. By adding this method to a class the compiler will call it to lookup any &#8220;name&#8221; on a class that it cannot find using its normal mechanisms. Note that this WILL make it so you no longer get compilation errors. So IF you use operator_lookup you need to make sure you have a means to debug any errors (like a break statement or something in you implementation to catch any typo&#8217;s)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With those warnings out of the way how can you make use of this ?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In normal code you might never need to. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, if you suppose you have a class that is dynamically configured and used like the following :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for each configProperty in classInstance.Configuration\n    \/\/ now use this property in some generic way \n    \/\/ maybe like an inspector that can edit anything \n    inspector.EditProperty configProperty\nnext<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then its possible you can add a configuration property that can be manipulated in a generic way and you DO NOT know all of them ahead of time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Operator_Lookup lets you deal with this.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And it can be both a GETTER and a SETTER.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ll find some <a href=\"https:\/\/ifnotnil.com\/t\/operator-convert\/1533\">sample code<\/a> in a series of posts I made about this topic <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In code I&#8217;ve been writing I&#8217;ve found a need to be able to &#8220;add properties&#8221; &#8211; but not in a conventional way. Normally I&#8217;d just add a property to some class in my Xojo code and be off &amp; running. But now I&#8217;m needing to be able to define &#8220;classes&#8221; (They&#8217;re not really classes) in &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2021\/02\/19\/operator_lookup\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Operator_Lookup&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-1087","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1087","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/comments?post=1087"}],"version-history":[{"count":1,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1087\/revisions"}],"predecessor-version":[{"id":1088,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1087\/revisions\/1088"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=1087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=1087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=1087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}