How to obtain the type information of "t"?
How to get the type name of t
class Test
{
void main()
{
var t = new Test();
t.Equals(null);// object.Equals
//How do I get the type of "t" ?
}
}
private static void AnalyzeNode(SyntaxNodeAnalysisContext context)
{
var invocationExpr = (InvocationExpressionSyntax)context.Node;
var memberAccessExpr = invocationExpr.Expression as MemberAccessExpressionSyntax;
if (memberAccessExpr == null)
return;
if (memberAccessExpr.Name.ToString() != nameof(object.Equals))
return;
var memberSymbol = context.SemanticModel.GetSymbolInfo(memberAccessExpr).Symbol as IMethodSymbol;
if (memberSymbol == null)
return;
_ = memberSymbol.ContainingType.SpecialType;// Object
}
I don't know why, but I cannot enter the breakpoint when debugging with vs. So I can only debug in this way, but I can't find the correct method.
var str = memberSymbol.ContainingSymbol?.Name + Environment.NewLine
+ memberSymbol.AssociatedSymbol?.Name + Environment.NewLine
+ memberSymbol.ContainingType?.Name + Environment.NewLine
+ memberSymbol.ContainingType?.SpecialType + Environment.NewLine
+ memberSymbol.ContainingType?.ContainingType?.Name + Environment.NewLine
+ memberSymbol.ContainingType?.TypeKind + Environment.NewLine
+ memberSymbol.ContainingType?.OriginalDefinition?.Name + Environment.NewLine
+ memberSymbol.ContainingType?.BaseType?.Name + Environment.NewLine
+ memberSymbol.ContainingType?.MetadataName + Environment.NewLine
+ memberSymbol.ContainingType?.ContainingAssembly?.Name + Environment.NewLine
+ string.Join(" ", memberSymbol.ContainingType?.MemberNames ?? Enumerable.Empty<string>()) + Environment.NewLine
+ "***************" + Environment.NewLine
+ invocationExpr.FullSpan.ToString() + Environment.NewLine
;
File.WriteAllText(@"xxxxxxx", str);
I want to obtain "Test" type information or type string