Esempio n. 1
0
        /// <summary>
        /// Generates the name of a component column for a given property type according to the naming conventions configuration
        /// </summary>
        /// <param name="property">The component child property</param>
        /// <param name="parentProperty">The entity parent property</param>
        /// <returns>The column name</returns>
        public string ToComponentColumnName(MemberInfo property, MemberInfo parentProperty)
        {
            string result = null;

            switch (namingConventions.ComponentsColumnsNamingConvention)
            {
            case ComponentsColumnsNamingConvention.PropertyName: result = ToColumnName(property); break;

            case ComponentsColumnsNamingConvention.ComponentNamePropertyName: result = ToColumnName(string.Concat(property.DeclaringType.Name, property.Name)); break;

            case ComponentsColumnsNamingConvention.ComponentName_PropertyName: result = string.Format(ConventionFormats.RelationshipUnderscoreSeparated, ToColumnName(property.DeclaringType.Name), ToColumnName(property.Name)); break;

            case ComponentsColumnsNamingConvention.EntityPropertyNameComponentPropertyName: result = ToColumnName(string.Concat(parentProperty.Name, property.Name)); break;

            case ComponentsColumnsNamingConvention.EntityPropertyName_ComponentPropertyName: result = string.Format(ConventionFormats.RelationshipUnderscoreSeparated, ToColumnName(parentProperty.Name), ToColumnName(property.Name)); break;

            case ComponentsColumnsNamingConvention.Custom:
            {
                if (namingConventions.ComponentsColumnsCustomNamingConvention == null)
                {
                    throw new ConfigurationErrorsException(string.Format(ExceptionMessages.CustomConventionNotFound, typeof(ComponentsColumnsNamingConvention).Name));
                }

                result = namingConventions.ComponentsColumnsCustomNamingConvention(property.DeclaringType, property);
            }; break;
            }

            return(result);
        }