Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to filter 'complex' types
Message
De
30/12/2014 03:17:37
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
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:
01612827
Vues:
30
Don't see why a simple .IsValueType on its own would not be enough. But it depends on your 'etc'.
It would include user defined structs and enums
http://msdn.microsoft.com/en-us/library/s1ax56ch.aspx

>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.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform