Detecting if class property is a reference type

前端 未结 7 633
广开言路
广开言路 2020-12-09 14:44

Is it possible when looking at a class\' properties to detect if any of them is a reference type.

Take below as an example:

public class Client
{
            


        
7条回答
  •  盖世英雄少女心
    2020-12-09 15:40

    You can enumerate the properties via Reflection, and check them:

    bool ContainsOnlyValues() { 
        return typeof(ProgrammeClient).GetProperties().All(x => x.PropertyType.IsValueType);
    }
    

提交回复
热议问题