c# - Using Roslyn, how to check if class comes from a local project, not the BCL or Nuget (etc)? -


i want write roslyn code analyser; needs work out if objectcreationexpression creating object local class (either in current project or project in current solution); or if class comes somewhere else, base class library or nuget package etc.

how tell class comes in roslyn?

you can of semantic model. can symbol constructor, , check type comes via locations or declaringsyntaxreferences, e.g.:

// objectcreationexpression node == ...; // semanticmodel model = ...; var symbol = model.getsymbolinfo(node).symbol; // constructor symbol var type = symbol.containingtype; // class symbol var isfromsource = type.declaringsyntaxreferences.length > 0 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -