I have 2 methods:
public void Method1(object[] args); // In Class A
public void Method2(string a, SomeClass b); // In Class B
And 2 Classes:
public class SomeClass {}
public class FromSomeClass : SomeClass {}
And a code that I analyze using Roslyn:
var c = new FromSomeClass();
Method1("a", c);
I want to analyze Method1 Call and check if it also a valid Method2 Call, meaning:
Method2("a", c); // will this run ok?
I got to the point where I got Method2 from the semantic model (IParameterSymbol) and for each argument in the invocation I have the I have the ITypeSymbol. How do I check if the argument type is valid for this IParameterSymbol? (both inheritance and implicit conversion)?
You can call CSharpCompilation.ClassifyConversion
or VisualBasicCompilation.ClassifyConversion
to figure out if a conversion exists. Note that the methods are language-specific since each language has some unique rules for conversions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.