How to use method parameter attributes

前端 未结 3 524
故里飘歌
故里飘歌 2021-01-04 05:58

I\'ve been struggling to find examples of how to write a custom attribute to validate method parameters, i.e., turn this form:

public void DoSomething(Client         


        
3条回答
  •  半阙折子戏
    2021-01-04 06:37

    Attributes are not enough for doing it.

    If I understood you correctly you want to add an attribute on a parameter in order to validate it at run time and that is impossible only with attributes.

    It is impossible because attributes are only "metadata" and not executed code.

    You will need some "real" code to read it and act accordingly. That code can be injected at compile time or you can hook into the function execution.

提交回复
热议问题