Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to filter 'complex' types
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
How to filter 'complex' types
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01612785
Message ID:
01612785
Vues:
40
UPDATE.

This seemed to work for me
 if (pi.PropertyType.IsValueType || pi.PropertyType == typeof(object) || Type.GetTypeCode(pi.PropertyType) != TypeCode.Object)
Hi everybody,

We have the following code
 foreach (PropertyInfo pi in searchCriteriaType.GetProperties())
                {
                    if (!pi.GetType().IsGenericType)
                    {
                        SearchCriteriaAttribute searchCriteriaAttribute = (SearchCriteriaAttribute)pi.GetCustomAttribute(typeof(SearchCriteriaAttribute));

                        if (searchCriteriaAttribute != null)
                        {
                            FilterItem filterItem = BuildFilterItem(searchCriteriaViewModel, searchCriteriaAttribute, pi);

                            if (filterItem != null)
                            {
                                filters.Add(filterItem);
                            }
                        }
                    }

                    filter.Filters = filters;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return filter;
        }
I attempted to add a check for IsGenericType, but it doesn't work (returns false and the next code is executed). Basically, I only want to perform the next logic if the pi is one of the following (String, DateTime, Boolean, Decimal, Int, etc. (nullable types)). I checked this question http://stackoverflow.com/questions/2442534/how-to-test-if-type-is-primitive but I don't want to create a new method or list the types. Is there any other way here? In particular, I have two properties which are generic lists and I want to somehow filter them out.

Thanks a lot in advance.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform