How to determine if all objects are serializable in a given namespace?

前端 未结 2 813
萌比男神i
萌比男神i 2021-01-14 04:37

Some background: We require all of our DTO objects to be serializable so that they can be stored in session or cached.

As you can imagine, this is extremely annoying

2条回答
  •  心在旅途
    2021-01-14 04:58

    One tool you might like to think about, that is easily integrated into your build, is NDepend. This lets you run various code metrics, which you can then use to warn/fail your build.

    In CQL (the built in query language in NDepend), you would write something like:

    WARN IF Count > 0 IN SELECT TYPES FROM NAMESPACES "namespace" WHERE !IsSerializable  
    

    Obviously this will only find namespaces for types that are included in assemblies within your solution, but I assume that's what you mean.

    NDepend can be run automatically as part of your build within VS, or on a seperate build server. It can also be run as a standalone application.

提交回复
热议问题