Dynamic wrapper around XAttribute
Inheritance: System.Dynamic.DynamicObject
Beispiel #1
0
        /// <summary>
        /// Creates dynamic wrapper around XAttribute
        /// </summary>
        public static dynamic AsDynamic(this XAttribute attribute)
        {
            Contract.Requires(attribute != null);
            Contract.Ensures(Contract.Result <object>() != null);

            return(DynamicXAttribute.CreateInstance(attribute));
        }
        //---------------------------------------------------------------------------------------//
        // Public Interface
        //---------------------------------------------------------------------------------------//

        #region Public Interface

        /// <summary>
        /// Indexer that returns XAttribute by XNode
        /// </summary>
        public dynamic this[XName name]
        {
            get
            {
                Contract.Requires(name != null);

                XAttribute attribute = element.Attribute(name);

                if (attribute == null)
                {
                    throw new InvalidOperationException("Attribute not found. Name: " + name.LocalName);
                }

                return(DynamicXAttribute.CreateInstance(attribute));
            }

            set
            {
                element.SetAttributeValue(name, value);
            }
        }