How to find out if a field does exists ?

Posts   
 
    
methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 12-Jul-2017 11:02:34   

Hello,

I have some code which is trying to generate a filter (WHERE statement) automatically using queryspec.

What I have is the name of the entity field class e.g. CustomerFields. Now I want to test if it has a particular field.

I found EntityFieldFactory where the create method has two string params. The problem is, if the field doesn't exists it throws an null exception.

Is there any other way where how to test if the entity has a particular field without throwing an exception if the field doesnt exist ? (return null, or false)

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 12-Jul-2017 22:13:35   

Do you have an object of that entity? If, yes then you can query the Fields collection.

Otherwise you can use:

typeof(CustomerFields).GetProperty("Country") != null;