Beispiel #1
0
        public static string GetKeyPropertyName <T>()
        {
            PropertyInfo[] props = typeof(T).GetProperties();
            foreach (PropertyInfo prop in props)
            {
                object[] attrs = prop.GetCustomAttributes(true);
                foreach (object attr in attrs)
                {
                    SearchablePropertyAttribute propertyAttribute = attr as SearchablePropertyAttribute;
                    if (propertyAttribute != null)
                    {
                        if (propertyAttribute.IsKey)
                        {
                            return(prop.Name);
                        }
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        public static Dictionary <PropertyInfo, SearchablePropertyAttribute> GetSearchableProperties <T>()
        {
            Dictionary <PropertyInfo, SearchablePropertyAttribute> searchableProperties = new Dictionary <PropertyInfo, SearchablePropertyAttribute>();

            PropertyInfo[] props = typeof(T).GetProperties();
            foreach (PropertyInfo prop in props)
            {
                object[] attrs = prop.GetCustomAttributes(true);
                foreach (object attr in attrs)
                {
                    SearchablePropertyAttribute propertyAttribute = attr as SearchablePropertyAttribute;
                    if (propertyAttribute != null)
                    {
                        if (propertyAttribute.IsSearchable)
                        {
                            searchableProperties.Add(prop, propertyAttribute);
                        }
                    }
                }
            }

            return(searchableProperties);
        }