AmazedSaint.Elastic.Lib.ElasticObject.CreateOrGetAttribute C# (CSharp) Метод

CreateOrGetAttribute() приватный Метод

Add a member to this element, with the specified value
private CreateOrGetAttribute ( string memberName, object value ) : ElasticObject
memberName string
value object
Результат ElasticObject
        internal ElasticObject CreateOrGetAttribute(string memberName, object value)
        {
            if (!HasAttribute(memberName))
            {
                AddAttribute(memberName, new ElasticObject(memberName,value));
            }

            return Attribute(memberName);
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Build an expando from an XElement
        /// </summary>
        /// <param name="el"></param>
        /// <returns></returns>
        public static ElasticObject ElasticFromXElement(XElement el)
        {
            var exp = new ElasticObject();

            if (!string.IsNullOrEmpty(el.Value))
                exp.InternalValue = el.Value;

            exp.InternalName = el.Name.LocalName;

            foreach (var a in el.Attributes())
                exp.CreateOrGetAttribute(a.Name.LocalName, a.Value);

            var textNode= el.Nodes().FirstOrDefault();
             if (textNode is XText)
                {
                    exp.InternalContent = textNode.ToString();
                }

            foreach (var c in el.Elements())
            {

                var child = ElasticFromXElement(c);
                child.InternalParent = exp;
                exp.AddElement(child);
            }
            return exp;
        }