罗斯林解决参数类型 [英] Resolving parameter type in Roslyn

查看:233
本文介绍了罗斯林解决参数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用罗斯林来实现自定义业务规则。此刻,我有点卡住了,我已经是被调用的方法时以验证参数的类型。没有问题验证,该方法被调用或者说是包含参数。
我必须使用GetSymbolInfo让我当前的语法的符号解析IdentifierNameSyntax。这不是null,并且具有我正在寻找诸如以下的信息:

I'm using Roslyn to implement custom business rules. 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. It's not null and has the information I'm looking for such as the following :

CandidateReason: None
CandidateSymbols: Length = 0
Symbol: Local System.Threading.Tasks.TaskScheduler ui

当我得到进入符号属性,我要验证该UI变量的确是的TaskScheduler,但它已经几天不成功的操作..基本上,这里的信息我得到的,当我在我的符号

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

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 :


  • 的ToString()上的符号

  • OrigninalDefinition
  • 的ToString()OriginalDefinition

  • ToDisplayString()
  • 试图到达类型,但我只可以看到它在运行时....

  • ToString() on OriginalDefinition
  • ToDisplayString() on OrigninalDefinition
  • ToString() on Symbol
  • Tried to reach type, but I can only see it in the runtime....

如果需要,我可以提供样品代码,但我不能分享我做的代码。
对于那些谁可能不知道,控制台应用程序正在仿真而下TDD,我们有我们自己创建单元测试工具。但它有任何对这个特定的情况没有影响。
感谢您的帮助,我真的很感激!

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. But it has no impact whatsoever on this particular situation. Thanks for the help, I really appreciate it !

推荐答案

您需要转换的 ISymbol ILocalSymbol ,这是公开的。结果
然后,您可以使用键入属性。

You need to cast the ISymbol to ILocalSymbol, which is public.
You can then use the Type property.

这篇关于罗斯林解决参数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆