public string ResolveCollectionName(Type type)
        {
            ICollectionPropertySetting collectionProperty = null;

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

            if (collectionProperty.CollectionName != null)
            {
                return(collectionProperty.CollectionName);
            }

            ICollectionPropertySetting collectionAttribute = CollectionPropertySetting.FindCollectionAttributeForType(type);

            if (collectionAttribute != null && collectionAttribute.CollectionName != null)
            {
                return(collectionAttribute.CollectionName);
            }

            return(type.Name);
        }
        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);
        }
예제 #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);
        }