Westwind.Utilities.Expando.this C# (CSharp) Method

this() public method

Convenience method that provides a string Indexer to the Properties collection AND the strongly typed properties of the object by name. // dynamic exp["Address"] = "112 nowhere lane"; // strong var name = exp["StronglyTypedProperty"] as string;
The getter checks the Properties dictionary first then looks in PropertyInfo for properties. The setter checks the instance properties before checking the Properties dictionary.
public this ( string key ) : object
key string
return object
        public object this[string key]
        {
            get
            {
                try
                {
                    // try to get from properties collection first
                    return Properties[key];
                }
                catch (KeyNotFoundException)
                {
                    // try reflection on instanceType
                    object result = null;
                    if (GetProperty(Instance, key, out result))
                        return result;

                    // nope doesn't exist
                    throw;
                }
            }
            set
            {
                if (Properties.ContainsKey(key))
                {
                    Properties[key] = value;
                    return;
                }

                // check instance for existance of type first
                var miArray = InstanceType.GetMember(key, BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.Instance);
                if (miArray != null && miArray.Length > 0)
                    SetProperty(Instance, key, value);
                else
                    Properties[key] = value;
            }
        }