Exemplo n.º 1
0
        public void CreateChangedDocument(JObject oldObject, JObject newObject, ref JObject changedObject, bool handleInnerObjects = false)
        {
            if (oldObject == null || oldObject.Type == JTokenType.Null)
            {
                changedObject = newObject;
                return;
            }

            foreach (var n in newObject)
            {
                if (!handleInnerObjects && ArangoAttributes.IsSystemAttribute(n.Key))
                {
                    continue;
                }

                JToken newValue = n.Value;
                JToken oldValue = oldObject[n.Key];

                if (newValue.Type == JTokenType.Object)
                {
                    JObject subChangeObject = new JObject();

                    CreateChangedDocument(oldValue as JObject, newValue as JObject, ref subChangeObject, handleInnerObjects: true);
                    if (subChangeObject.Count != 0)
                    {
                        changedObject.Add(n.Key, subChangeObject);
                    }
                }
                else if (!JObject.DeepEquals(oldValue, newValue))
                {
                    changedObject.Add(n.Key, newValue);
                }
            }
        }
Exemplo n.º 2
0
        protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
        {
            IList <JsonProperty> properties = base.CreateProperties(type, memberSerialization);

            IList <JsonProperty> convertedProperties = new List <JsonProperty>();

            foreach (var p in properties)
            {
                IDocumentPropertySetting documentProperty = null;
                sharedSetting.Collection.ChangeDocumentPropertyForType(type, p.UnderlyingName, x => documentProperty = x);
                if (documentProperty != null)
                {
                    if (documentProperty.IgnoreProperty)
                    {
                        continue;
                    }
                }

                p.PropertyName = sharedSetting.Collection.ResolvePropertyName(type, p.UnderlyingName);

                if (ArangoAttributes.IsDocumentSystemAttribute(p.PropertyName))
                {
                    p.NullValueHandling = NullValueHandling.Ignore;
                }

                convertedProperties.Add(p);
            }

            return(convertedProperties);
        }
Exemplo n.º 3
0
        internal string ResolvePropertyName(Type type, string memberName)
        {
            IDocumentPropertySetting documentProperty = null;

            ChangeDocumentPropertyForType(type, memberName, x => documentProperty = x);

            /*************   defined setting   **************/

            // * return defined setting identifier
            var docAttributeName = documentProperty.Identifier.ToAttributeName();

            if (docAttributeName != null)
            {
                return(docAttributeName);
            }

            // * return defined setting name
            if (documentProperty.PropertyName != null)
            {
                return(documentProperty.PropertyName);
            }

            // * return defined setting naming convention
            if (documentProperty.Naming == NamingConvention.ToCamelCase)
            {
                return(StringUtils.ToCamelCase(memberName));
            }

            /*************   attribute setting   **************/

            var attributeProperty = DocumentPropertySetting.FindDocumentAttributeForType(type, memberName);

            if (attributeProperty != null)
            {
                // * return attribute setting identifier
                var attributeName = attributeProperty.Identifier.ToAttributeName();
                if (attributeName != null)
                {
                    return(attributeName);
                }

                // * return defined setting name
                if (attributeProperty.PropertyName != null)
                {
                    return(attributeProperty.PropertyName);
                }

                // * return defined setting naming convention
                if (attributeProperty.Naming == NamingConvention.ToCamelCase)
                {
                    return(StringUtils.ToCamelCase(memberName));
                }
            }

            /*************   default identifer setting for type   **************/
            var allIdentifierTypes = ArangoAttributes.GetAllIdentifierTypes();

            string defaultName = null;

            foreach (IdentifierType idType in allIdentifierTypes)
            {
                if (FindIdentifierDefaultNameForType(type, idType, memberName) ||
                    (defaultIdentifierNames.TryGetValue(idType, out defaultName) && defaultName == memberName))
                {
                    return(idType.ToAttributeName());
                }
            }

            /*************   collection setting   **************/

            ICollectionPropertySetting collectionProperty = null;

            ChangeCollectionPropertyForType(type, x => collectionProperty = x);

            // * return defined setting collection naming convention
            if (collectionProperty.Naming == NamingConvention.ToCamelCase)
            {
                return(StringUtils.ToCamelCase(memberName));
            }


            /*************  attribute collection setting   **************/

            ICollectionPropertySetting collectionAttribute = CollectionPropertySetting.FindCollectionAttributeForType(type);

            if (collectionAttribute != null)
            {
                if (collectionAttribute.Naming == NamingConvention.ToCamelCase)
                {
                    return(StringUtils.ToCamelCase(memberName));
                }
            }

            return(memberName);
        }