How to iterate through each property of a custom vb.net object?

后端 未结 4 1806
囚心锁ツ
囚心锁ツ 2020-12-07 21:25

How can I go through each of the properties in my custom object? It is not a collection object, but is there something like this for non-collection objects?

         


        
4条回答
  •  太阳男子
    2020-12-07 21:31

    You can use reflection... With Reflection you can examine every member of a class (a Type), proeprties, methods, contructors, fields, etc..

    using System.Reflection;
    
    Type type = job.GetType();
        foreach ( MemberInfo memInfo in type.GetMembers() )
           if (memInfo is PropertyInfo)
           {
                // Do Something
           }
    

提交回复
热议问题