Beispiel #1
0
        /// <summary>
        /// Indexer for attribute selection, processing constructed attributes.
        /// </summary>
        /// <param name="name">The display name of the attribute</param>
        /// <returns>The value of the attribute which is computed if constructed or retrieved from the
        /// attribute list otherwise. Is null if the attribute has not value associated.</returns>
        public Value this[string name]
        {
            get
            {
                name = name.ToLower();
                ConstructedAttributeGetter getter;
                if (constructedAttributeGetters.TryGetValue(name, out getter))
                {
                    // This is a constructed attribute and has a special meaning
                    return(getter(this));
                }
                else
                {
                    // This is a stored attribute and is handled generically
                    Value result;
                    if (attributes.TryGetValue(name, out result))
                    {
                        return(result);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            set
            {
                name = name.ToLower();
                Assert.IsTrue(
                    !constructedAttributeGetters.ContainsKey(name),
                    "constructed attribute '{0}' cannot be set",
                    name);
                attributes[name] = value;
            }
        }