[英]Resolving parameter type in Roslyn
I'm using Roslyn to implement custom business rules. 我正在使用Roslyn来实现自定义业务规则。 At the moment, I'm a bit stuck, I have to validate the type of a parameter when a method is being invoked.
目前,我有点卡住了,我必须在调用方法时验证参数的类型。 There are no issues validating that the method is being invoked or that is contains parameters.
验证方法正在被调用或包含参数没有问题。 I have resolve an IdentifierNameSyntax by using GetSymbolInfo to get the symbol of my current syntax.
我已使用GetSymbolInfo解析IdentifierNameSyntax以获取当前语法的符号。 It's not null and has the information I'm looking for such as the following :
它不是null并且有我正在寻找的信息,如下所示:
CandidateReason: None
CandidateSymbols: Length = 0
Symbol: Local System.Threading.Tasks.TaskScheduler ui
When I get into the Symbol property, I want to validate that the ui variable is indeed a TaskScheduler, but it has been an unsuccessful operation for a few days.. Basically, here's the info I get when I'm in Symbol 当我进入Symbol属性时,我想验证ui变量确实是一个TaskScheduler,但它已经是一个不成功的操作几天了......基本上,这是我在Symbol中的信息
Local System.Threading.Tasks.TaskScheduler ui
CanBeReferencedByName: true
ConstantValue: null
ContainingAssembly: Assembly TestProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
ContainingNamespace: Namespace ConsoleApplication1
ContainingSymbol: Method void ConsoleApplication1.TypeName.Test()
ContainingType: NamedType ConsoleApplication1.TypeName
DeclaredAccessibility: NotApplicable
DeclaringSyntaxReferences: Length = 1
HasConstantValue: false
HasUnsupportedMetadata: false
HighestPriorityUseSiteError: 2147483647
IsAbstract: false
IsCatch: false
IsConst: false
IsDefinition: true
IsExtern: false
IsFixed: false
IsFor: false
IsForEach: false
IsImplicitlyDeclared: false
IsOverride: false
IsSealed: false
IsStatic: false
IsUsing: false
IsVar: true
IsVirtual: false
Kind: Local
Language: "C#"
Locations: Length = 1
MetadataName: "ui"
Name: "ui"
OriginalDefinition: Local System.Threading.Tasks.TaskScheduler ui
OriginalSymbolDefinition: Local System.Threading.Tasks.TaskScheduler ui
Type: NamedType System.Threading.Tasks.TaskScheduler
binder: {Microsoft.CodeAnalysis.CSharp.BlockBinder}
Here's what I have so far to get the type of ui : 这是我到目前为止得到的ui类型:
If needed, I can provided sample code but I cannot share the code I did. 如果需要,我可以提供示例代码,但我无法共享我所做的代码。 For those who might wonder, the console application is being simulated while under TDD, we have our own tool for creating unit test.
对于那些可能想知道的人,在TDD下模拟控制台应用程序,我们有自己的工具来创建单元测试。 But it has no impact whatsoever on this particular situation.
但它对这种特殊情况没有任何影响。 Thanks for the help, I really appreciate it !
感谢您的帮助,我真的很感激!
You need to cast the ISymbol
to ILocalSymbol
, which is public. 你需要转换
ISymbol
到ILocalSymbol
,这是公开的。
You can then use the Type
property. 然后,您可以使用
Type
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.