What is the smoothest, most appealing syntax you've found for asserting parameter correctness in c#?

后端 未结 14 1949
一个人的身影
一个人的身影 2020-12-22 23:50

A common problem in any language is to assert that parameters sent in to a method meet your requirements, and if they don\'t, to send nice, informative error messages. This

14条回答
  •  感动是毒
    2020-12-23 00:34

    Don't know if this technique transfers from C/C++ to C#, but I've done this with macros:

    
        #define CHECK_NULL(x)  { (x) != NULL || \
               fprintf(stderr, "The value of %s in %s, line %d is null.\n", \
               #x, __FILENAME__, __LINE__); }
     

提交回复
热议问题