Reputation: 2903
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
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 :
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 !
Upvotes: 3
Views: 1789
Reputation: 888077
You need to cast the ISymbol
to ILocalSymbol
, which is public.
You can then use the Type
property.
Upvotes: 4