GetProperty() SetProperty()

I created the GetProperty() and SetProperty() methods to allow the base object to manage holding the variables needed for the object. I’ve implemented these methods on my old object classes just to test them out in some real world examples. I’ve found two problems, the first is that sometimes I only want to set a new value if the old value changed, so I created isPropertyDifferent() that will return true or false if the property’s value is different from the specified value. This is more useful than making the SetProperty() check it because now I can do extra processing depending on the result.

        ///
        /// Will return true if the value is different
        ///
        protected bool isPropertyDifferent(string name, object value)
        {
            //Check if it exists yet
            if (_properties.ContainsKey(name))
            {
                //Check if it's different
                if (_properties[name] == value)
                {
                    return false;
                }
            }
            //It's different or it doesn't exist.
            return true;
        }

The other issue is that right now GetProperty() only takes a value to use as the default if the Property doesn’t currently exist. But what if I want it to call a function instead? In fact that’s exactly what I want. If tags doesn’t exist, I want you to go fetch them, but I don’t want you to waste time fetching them if the value already exists (which is what It’ll do with the current implementation) so I need to figure out a simple way to use delegates here.

Share

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv Enabled