Exemple #1
0
        //// ---------------------------------------------------------------
        /// <summary>
        /// Serialises the entity to xml to pass to the SDK webservices
        /// </summary>
        /// <param name="ommitRoot"></param>
        /// <returns></returns>
        public string Serialise(bool?ommitRoot)
        {
            string xml = "";

            if (ommitRoot == null || ommitRoot == false)
            {
                xml += "<a:Entity>";
            }

            xml += "<a:Attributes>";

            Dictionary <string, object> record = (Dictionary <string, object>)((object)this);

            // Check primary key attribute - Guid's can't have a null value
            if (record[this.LogicalName + "id"] == null)
            {
                record.Remove(this.LogicalName + "id");
            }
            foreach (string key in record.Keys)
            {
                // Exclude the built in properties
                if ((bool)Script.Literal(@"typeof({0}[{1}])!=""function""", record, key) &&
                    (bool)Script.Literal("Object.prototype.hasOwnProperty.call({0}, {1})", this, key) &&
                    !StringEx.IN(key, new string[] { "id", "logicalName", "entityState", "formattedValues" }) && !key.StartsWith("$") && !key.StartsWith("_"))
                {
                    object attributeValue = record[key];
                    if (!FormattedValues.ContainsKey(key))
                    {
                        xml += Attribute.Serialise(key, attributeValue, _metaData);
                    }
                }
            }

            xml += "</a:Attributes>";
            xml += "<a:LogicalName>" + this.LogicalName + "</a:LogicalName>";
            if (this.Id != null)
            {
                xml += "<a:Id>" + this.Id + "</a:Id>";
            }
            if (ommitRoot == null || ommitRoot == false)
            {
                xml += "</a:Entity>";
            }

            return(xml);
        }