How to validate a parameter's type in method when using Roslyn

后端 未结 1 518
逝去的感伤
逝去的感伤 2021-01-23 15:01

I\'m doing code analysis with Roslyn in order to validate that even though I have the following signature

public void MyMethod(object anObject, MyCustomObject cu         


        
相关标签:
1条回答
  • 2021-01-23 15:47

    What you should be doing is getting the arguments (not parameters -- they are different things!) and calling SemanticModel.GetTypeInfo() on the ArgumentSyntax. That'll give you the type of the expression being passed. From there you can do whatever checks you need.

    0 讨论(0)
提交回复
热议问题