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 (p.PropertyName == "_key" || p.PropertyName == "_id" || p.PropertyName == "_rev")
                {
                    p.NullValueHandling = NullValueHandling.Ignore;
                }

                convertedProperties.Add(p);
            }

            return(convertedProperties);
        }
        internal string ResolvePropertyName(Type type, string memberName)
        {
            IDocumentPropertySetting documentProperty = null;

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

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

            // * return defined setting identifier
            if (documentProperty.Identifier != IdentifierType.None)
            {
                switch (documentProperty.Identifier)
                {
                case IdentifierType.Key:
                    return("_key");

                case IdentifierType.Handle:
                    return("_id");

                case IdentifierType.Revision:
                    return("_rev");

                case IdentifierType.EdgeFrom:
                    return("_from");

                case IdentifierType.EdgeTo:
                    return("_to");
                }
            }

            // * 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
                if (attributeProperty.Identifier != IdentifierType.None)
                {
                    switch (attributeProperty.Identifier)
                    {
                    case IdentifierType.Key:
                        return("_key");

                    case IdentifierType.Handle:
                        return("_id");

                    case IdentifierType.Revision:
                        return("_rev");

                    case IdentifierType.EdgeFrom:
                        return("_from");

                    case IdentifierType.EdgeTo:
                        return("_to");
                    }
                }

                // * 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   **************/

            if (FindIdentifierDefaultNameForType(type, IdentifierType.EdgeFrom, memberName))
            {
                return("_from");
            }
            if (FindIdentifierDefaultNameForType(type, IdentifierType.EdgeTo, memberName))
            {
                return("_to");
            }
            if (FindIdentifierDefaultNameForType(type, IdentifierType.Handle, memberName))
            {
                return("_id");
            }
            if (FindIdentifierDefaultNameForType(type, IdentifierType.Revision, memberName))
            {
                return("_rev");
            }
            if (FindIdentifierDefaultNameForType(type, IdentifierType.Key, memberName))
            {
                return("_key");
            }

            /*************   default identifer setting   **************/

            // * return defined default identifier name
            string defaultName = null;

            if (defaultIdentifierNames.TryGetValue(IdentifierType.EdgeFrom, out defaultName))
            {
                if (defaultName == memberName)
                {
                    return("_from");
                }
            }
            if (defaultIdentifierNames.TryGetValue(IdentifierType.EdgeTo, out defaultName))
            {
                if (defaultName == memberName)
                {
                    return("_to");
                }
            }
            if (defaultIdentifierNames.TryGetValue(IdentifierType.Handle, out defaultName))
            {
                if (defaultName == memberName)
                {
                    return("_id");
                }
            }
            if (defaultIdentifierNames.TryGetValue(IdentifierType.Key, out defaultName))
            {
                if (defaultName == memberName)
                {
                    return("_key");
                }
            }
            if (defaultIdentifierNames.TryGetValue(IdentifierType.Revision, out defaultName))
            {
                if (defaultName == memberName)
                {
                    return("_rev");
                }
            }

            /*************   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);
        }
Ejemplo 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);
        }