Exemple #1
0
        static string EnumDisplay(string value, NHibernate.Mapping.Property property)
        {
            if (String.IsNullOrWhiteSpace(value))
            {
                return(null);
            }

            var enumType   = property.Type.ReturnedClass;
            var enumValues = enumType.GetFields();

            return(enumValues.FirstOrDefault(f => f.Name == value)?.GetEnumTitle());
        }
Exemple #2
0
        /// <summary>
        /// 获得Property的长度
        /// </summary>
        /// <param name="sessionFactory"></param>
        /// <param name="type"></param>
        /// <param name="fullPropertyName"></param>
        /// <returns></returns>
        public static int?GetPropertyLength(ISessionFactory sessionFactory, Type type, string fullPropertyName)
        {
            if (string.IsNullOrEmpty(fullPropertyName))
            {
                return(null);
            }
            string dictKey = type.ToString() + "#" + fullPropertyName;

            int?ret = null;

            if (!s_propertyLengths.ContainsKey(dictKey))
            {
                Configuration conf = GetSessionFactoryManager().GetConfigurationBySessionFactory(sessionFactory);
                if (conf != null)
                {
                    try
                    {
                        int idx = fullPropertyName.LastIndexOf(':');
                        if (idx == -1)
                        {
                            var persistentClass = conf.GetClassMapping(type);
                            if (persistentClass != null)
                            {
                                NHibernate.Mapping.Property property = persistentClass.GetProperty(fullPropertyName);
                                if (property != null)
                                {
                                    var it = property.ColumnIterator.GetEnumerator();
                                    it.MoveNext();
                                    int length = ((NHibernate.Mapping.Column)it.Current).Length;
                                    ret = length;
                                }
                            }
                        }
                        else
                        {
                            string left = fullPropertyName.Substring(0, idx);
                            bool   hasCollection;
                            Type   leftType = GetPropertyType(sessionFactory, type, left, out hasCollection);
                            ret = GetPropertyLength(sessionFactory, leftType, fullPropertyName.Substring(idx + 1));
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                s_propertyLengths[dictKey] = ret;
            }

            return(s_propertyLengths[dictKey]);
        }