Is there any way to get the list of system datatypes?

Viewed 51

I have a class with many properties with different types including some custom class types. Now I want to find those properties which are not of system types like :

  • System.Int32

  • System.Boolean

  • System.String

  • System.Decimal

  • and so on

Currently I am doing things like this way :

Dim objProperties As PropertyInfo() = GetType(MyClassType).GetProperties()

For Each objPropertyInfo As PropertyInfo In objProperties
    If Not objPropertyInfo.PropertyType() Is GetType(Int32) And Not objPropertyInfo.PropertyType() Is GetType(String) Then
        'other code
    End If
Next

If I can get the desired list, then the If condition could be more simple like :

If Not systemTypeList.Contains(objPropertyInfo.Name) Then
1 Answers

Thanks @D Stanley for the hint of a solution. I am wrapping up the solution.

Dim strProperties As New List(Of String)
Dim objProperties As PropertyInfo() = GetType(InvoiceType).GetProperties()

strProperties = objProperties.Where(Function(p) p.PropertyType.Namespace <> "System").Select(Function(p) p.Name).ToList()

Here I am generating the list of the properties which are not of any system types like String, Decimal etc So now, I can write the If condition easily like :

If strProperties.Contains(objPropertyInfo.Name) Then
Related