I want to merge two .cs files to create a third one. Can anyone help me please.
public partial class A
{
// some methods
}
suppose this code is written in a file A.cs
public partial class B
{
// some methods
}
and this code is written in a file B.cs.
I want to generate a new C.cs
having all the code of A.cs and B.cs ignoring namespaces.
I assume you indeed want to merge the partial definitions of the same class. If you really need to merge different classes into a single one, the code can be easily adjusted, but there will be no guarantee that it compiles (because, for example, the classes could have members with the same name).
The problem is quite complicated indeed because of the symbol meaning: it depends on the usings, so one needs to be really careful when merging them.
So the best idea would be not to try to analyse the code semantics manually, but to use a big hammer: Roslyn analyzer.
Let's start.
First of all, you'll need to install Extension Development Workload as it's described here. After this, you'll be able to create a Standalone code analysis tool project.
When you create it, you'll get a lot of useful boilerplate code like this:
class Program
{
static async Task Main(string[] args)
{
// ...
using (var workspace = MSBuildWorkspace.Create())
{
var solutionPath = args[0];
WriteLine($"Loading solution '{solutionPath}'");
var solution = await workspace.OpenSolutionAsync(solutionPath,
new ConsoleProgressReporter());
WriteLine($"Finished loading solution '{solutionPath}'");
// insert your code here
}
}
private static VisualStudioInstance SelectVisualStudioInstance(
VisualStudioInstance[] visualStudioInstances)
{
// ...
}
private class ConsoleProgressReporter : IProgress<ProjectLoadProgress>
{
// ...
}
}
Let's fill in what is needed.
Instead of // insert your code here let's put the following code:
var targetClass = args[1];
var modifiedSolution = await MergePartialClasses(targetClass, solution);
workspace.TryApplyChanges(modifiedSolution);
We'll need to implement the logic in MergePartialClasses. The name of the class should be passed as the second command line parameter.
Let's first add the following usings at the top:
using static System.Console;
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
Now we can start with the main method. I've put the comments about what's happening directly in the code.
static async Task<Solution> MergePartialClasses(string targetClass, Solution solution)
{
// https://stackoverflow.com/a/32179708/276994
// we loop through the projects in the solution and process each of the projects
foreach (var projectId in solution.ProjectIds)
{
var project = solution.GetProject(projectId);
WriteLine($"Processing project {project.Name}");
var compilation = await project.GetCompilationAsync();
// finding the type which we want to merge
var type = compilation.GetTypeByMetadataName(targetClass);
if (type == null)
{
WriteLine($"Type {targetClass} is not found");
return solution;
}
// look up number of declarations. if it's only 1, we have nothing to merge
var declarationRefs = type.DeclaringSyntaxReferences;
if (declarationRefs.Length <= 1)
{
WriteLine($"Type {targetClass} has only one location");
return solution;
}
// I didn't implement the case of nested types, which would require to
// split the outer class, too
if (type.ContainingType != null)
throw new NotImplementedException("Splitting nested types");
// we'll accumulate usings and class members as we traverse all the definitions
var accumulatedUsings = new List<UsingDirectiveSyntax>();
var classParts = new List<ClassDeclarationSyntax>();
foreach (var declarationRef in declarationRefs)
{
var declaration = (ClassDeclarationSyntax)await declarationRef.GetSyntaxAsync();
// get hold of the usings
var tree = declaration.SyntaxTree;
var root = await tree.GetRootAsync();
var usings = root.DescendantNodes().OfType<UsingDirectiveSyntax>();
accumulatedUsings.AddRange(usings);
// since we are trying to move the syntax into another file,
// we need to expand everything in order to remove the dependency
// on usings
// in order to do it, we use a custom CSharpSyntaxRewriter (defined later)
var document = project.GetDocument(tree);
var expander = new AllSymbolsExpander(document);
var expandedDeclaration = (ClassDeclarationSyntax)expander.Visit(declaration);
classParts.Add(expandedDeclaration);
// remove the old declaration from the place where it is
// we can't just remove the whole file as it may contain some other classes
var modifiedRoot =
root.RemoveNodes(new[] { declaration }, SyntaxRemoveOptions.KeepNoTrivia);
var modifiedDocument = document.WithSyntaxRoot(modifiedRoot);
project = modifiedDocument.Project;
}
// now, sort the usings and remove the duplicates
// in order to use DistinctBy, I added MoreLinq nuget package and added
// using MoreLinq; at the beginning
// https://stackoverflow.com/a/34063289/276994
var sortedUsings = accumulatedUsings
.DistinctBy(x => x.Name.ToString())
.OrderBy(x => x.StaticKeyword.IsKind(SyntaxKind.StaticKeyword) ?
1 : x.Alias == null ? 0 : 2)
.ThenBy(x => x.Alias?.ToString())
.ThenByDescending(x => x.Name.ToString().StartsWith(nameof(System) + "."))
.ThenBy(x => x.Name.ToString());
// now, we have to merge the class definitions.
// split the name into namespace and class name
var (nsName, className) = SplitName(targetClass);
// gather all the attributes
var attributeLists = List(classParts.SelectMany(p => p.AttributeLists));
// modifiers must be the same, so we are taking them from the
// first definition, but remove partial if it's there
var modifiers = classParts[0].Modifiers;
var partialModifier = modifiers.FirstOrDefault(
m => m.Kind() == SyntaxKind.PartialKeyword);
if (partialModifier != null)
modifiers = modifiers.Remove(partialModifier);
// gather all the base types
var baseTypes =
classParts
.SelectMany(p => p.BaseList?.Types ?? Enumerable.Empty<BaseTypeSyntax>())
.Distinct()
.ToList();
var baseList = baseTypes.Count > 0 ? BaseList(SeparatedList(baseTypes)) : null;
// and constraints (I hope that Distinct() works as expected)
var constraintClauses =
List(classParts.SelectMany(p => p.ConstraintClauses).Distinct());
// now, we construct class members by pasting together the accumulated
// per-part member lists
var members = List(classParts.SelectMany(p => p.Members));
// now we can build the class declaration
var classDef = ClassDeclaration(
attributeLists: attributeLists,
modifiers: modifiers,
identifier: Identifier(className),
typeParameterList: classParts[0].TypeParameterList,
baseList: baseList,
constraintClauses: constraintClauses,
members: members);
// if there was a namespace, let's put the class inside it
var body = (nsName == null) ?
(MemberDeclarationSyntax)classDef :
NamespaceDeclaration(IdentifierName(nsName)).AddMembers(classDef);
// now create the compilation unit and insert it into the project
// http://roslynquoter.azurewebsites.net/
var newTree = CompilationUnit()
.WithUsings(List(sortedUsings))
.AddMembers(body)
.NormalizeWhitespace();
var newDocument = project.AddDocument(className, newTree);
var simplifiedNewDocument = await Simplifier.ReduceAsync(newDocument);
project = simplifiedNewDocument.Project;
solution = project.Solution;
}
// finally, return the modified solution
return solution;
}
The rest is the AllSymbolsExpander, which just calls Simplifier.ExpandAsync for every node:
class AllSymbolsExpander : CSharpSyntaxRewriter
{
Document document;
public AllSymbolsExpander(Document document)
{
this.document = document;
}
public override SyntaxNode VisitAttribute(AttributeSyntax node) =>
Expand(node);
public override SyntaxNode VisitAttributeArgument(AttributeArgumentSyntax node) =>
Expand(node);
public override SyntaxNode VisitConstructorInitializer(ConstructorInitializerSyntax node) =>
Expand(node);
public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node) =>
Expand(node);
public override SyntaxNode VisitXmlNameAttribute(XmlNameAttributeSyntax node) =>
Expand(node);
public override SyntaxNode VisitTypeConstraint(TypeConstraintSyntax node) =>
Expand(node);
public override SyntaxNode DefaultVisit(SyntaxNode node)
{
if (node is ExpressionSyntax ||
node is StatementSyntax ||
node is CrefSyntax ||
node is BaseTypeSyntax)
return Expand(node);
return base.DefaultVisit(node);
}
SyntaxNode Expand(SyntaxNode node) =>
Simplifier.ExpandAsync(node, document).Result; //? async-counterpart?
}
and the trivial function SplitName:
static (string, string) SplitName(string name)
{
var pos = name.LastIndexOf('.');
if (pos == -1)
return (null, name);
else
return (name.Substring(0, pos), name.Substring(pos + 1));
}
That's all!
I wanted to merge all code generated files to create one file. After a lot of searches I achieved this task by creating a new class. Read all code first generated files, create their objects in my newly created class and call their Up() and Down() methods in it.
Note: Wrote a separate method a read all namespaces distinct. If anyone wants code I can share my code sample too.
Related
I'm trying to determine what the best way to get fully optimized delegates for various objects to improve the speed of serialization. Simply put: I'd like to remove various different checks, and compile more efficient serialize functions one time at the start of my app.
Let's take a look at this simple example:
public class GamePacket
{
[Length(10)]
[ReadBackwards]
public string Id { get; set; }
}
Now, I'd likely create a serializer, and for performance reasons store the attributes in a cached field. Everytime I want to deserialize a GamePacket from a stream (or byte array), I'd call something like:
Deserialize(byte[] stream)
{
var header = stream.ReadByte();
var packet = cachedDeserializers[header];
var instance = packet.DelegateForCreateInstance();
foreach (var field in packet.Fields)
{
if (field.Type != TypeCode.String) continue;
var str = stream.ReadBytes(field.LengthAttribute.Length);
if (field.HasReadBackwardsAttribute)
str = str.Reverse();
field.DelegateForSetValue(instance, str);
}
}
The problem now lies in the fact that EVERY time I'm calling Deserialize on that stream, I need to loop through and check various things like attributes, and other checks. In the example, these things can potentially be omitted (And maybe more):
if (field.Type != TypeCode.String) continue;
if (field.HasReadBackwardsAttribute)
If I know the field has a read backwards attribute, I'd like to compile a simplified delegate on app start that omits these checks, and simply reads it backwards. Is it possible to create a delegate that can remove unneeded logic? For example:
Deserialize(byte[] stream)
{
var header = stream.ReadByte();
var packet = cachedDeserializers[header];
var instance = packet.CallCachedCompile(stream);
}
// CallCachedCompile for GamePacket would look something like this:
CallCachedCompile(byte[] stream)
{
var instance = this.DelegateForCreateInstance();
var str = stream.ReadBytes(10);
str = str.Reverse();
this.DelegateForSetValue(instance, "Id", str);
return instance;
}
I've looked briefly into expression trees. Would something like this be doable in expression Trees? What would be the most efficient way?
Yes, using code generation approach you can generate delegates for the particular type. So instead of this generic reflection-like code:
foreach (var field in packet.Fields)
{
if (field.Type != TypeCode.String) continue;
var str = stream.ReadBytes(field.LengthAttribute.Length);
if (field.HasReadBackwardsAttribute)
str = str.Reverse();
field.DelegateForSetValue(instance, str);
}
You can generate code for a specific type:
gamePacketInstance.Id = SomeConvertionToString(stream.ReadBytes(field.LengthAttribute.Length).Revers());
The code generation topic is quite big and I don't know what exactly you do inside your delegates. You can generate specific delegates in runtime (emit il or expression trees) or in compile time (source generators). I suggest you to read my article Dotnet code generation overview by example. It will give good overview with examples.
Without using any code generation you can still do this pretty efficiently.
You basically need to use generics and polymorphism to cache all code that you want done for each type that you encounter.
Bearing in mind that properties have underlying methods, we can create delegates to set properties without using code generation.
abstract class DeserializerBase
{
object DeserializePacket(Stream stream);
}
class Deserializer<T> : DeserializerBase where T : new()
{
FieldAction<T>[] fieldActions =
typeof(T).GetProperties()
.Where(p => p.Type == TypeCode.String)
.Select(p => IsReverseAttribute(p)
? new FieldActionReverse<T>
{
Setter = p.SetMethod.CreateDelegate<Action<T, string>>(),
Length = GetLengthAttribute(p),
}
: new FieldAction<T>
{
Setter = p.SetMethod.CreateDelegate<Action<T, string>>(),
Length = GetLengthAttribute(p),
})
.ToArray();
object DeserializePacket(Stream stream);
{
var packet = new T();
foreach (var action in fieldActions)
action.Deserialize(packet);
}
}
class FieldAction<T>
{
public Action<T, string> Setter;
public int Length;
void Deserialize(Stream stream, T instance)
{
var str = ReadString(stream);
Setter(instance, str);
}
virtual string GetString(Stream stream)
{
return stream.ReadBytes(Length);
}
}
class FieldActionReverse<T> : FieldAction<T>
{
override string GetString(Stream stream)
{
return stream.ReadBytes(Length).Reverse();
}
}
Your final entry code becomes this.
Dictionary<int, DeserializerBase> cachedDeserializers = new Dictionary<int, DeserializerBase>
{
{5, new Deserializer<GamePacket>()}
};
Deserialize(Stream stream)
{
var header = stream.ReadByte();
var packet = cachedDeserializers[header].DeserializePacket(stream);
}
You can even place generic constraints on T to ensure it is a Packet then you can return a base Packet type from this entry function.
Given a list of MethodDeclarationSyntax I would like to collect all the methods in a solution that are calling this method transitively.
I have been using the following code:
var methods = new Stack<MethodDeclarationSyntax>();
... // fill methods with original method to start from
var visited = new HashSet<MethodDeclarationSyntax>();
while (methods.Count > 0)
{
var method = methods.Pop();
if (!visited.Add(method))
{
continue;
}
var methodSymbol = (await solution.GetDocument(method.SyntaxTree).GetSemanticModelAsync()).GetDeclaredSymbol(method);
foreach (var referencer in await SymbolFinder.FindCallersAsync(methodSymbol, solution))
{
var callingMethod = (MethodDeclarationSyntax) referencer.CallingSymbol.DeclaringSyntaxReferences[0].GetSyntax();
methods.Push(callingMethod);
}
}
The problem is that MethodDeclarationSyntax doesn't seem to be a singleton, so this loop is running forever, visiting the same methods again and again.
What is the proper way to uniquely identify a MethodDeclarationSyntax in a Dictionary/Hashset?
Edit 1)
As a workaround, I'm using the following MethodDeclarationSyntaxComparer to initialize my HashSet, but it looks very fragile:
private class MethodDeclarationSyntaxComparer: IEqualityComparer<MethodDeclarationSyntax>
{
public bool Equals(MethodDeclarationSyntax x, MethodDeclarationSyntax y)
{
var xloc = x.GetLocation();
var yloc = y.GetLocation();
return xloc.SourceTree.FilePath == yloc.SourceTree.FilePath &&
xloc.SourceSpan == yloc.SourceSpan;
}
public int GetHashCode(MethodDeclarationSyntax obj)
{
var loc = obj.GetLocation();
return (loc.SourceTree.FilePath.GetHashCode() * 307) ^ loc.SourceSpan.GetHashCode();
}
}
I'm wondering whether using SyntaxNode here is the right way to go.
Since you're already using SymbolFinder and you're using the semantic model, maybe the right way to go is to actually use ISymbols, rather than SyntaxNodes.
ISymbol already contains the SyntaxReferences you are using, so:
var methods = new Stack<IMethodSymbol>();
... // fill methods with original method to start from
... // convert methods to symbols via semanticModel.GetDeclaredSymbol (node);
var visited = new HashSet<IMethodSymbol>();
while (methods.Count > 0)
{
var method = methods.Pop();
if (!visited.Add(method))
{
continue;
}
foreach (var referencer in await SymbolFinder.FindCallersAsync(method, solution))
{
var callingMethod = (MethodDeclarationSyntax) referencer.CallingSymbol.DeclaringSyntaxReferences[0].GetSyntax();
methods.Push(callingMethod);
}
}
You could possibly make the visited hashset into a Dictionary<IMethodSymbol, IEnumerable<Location>>, and concat all the locations, and thus reconstruct the syntaxes from that result.
Currently I am working on simple code analyse for c# with roslyn. I need to parse all document of all projects inside one solution and getting the declared used classes inside this document.
For example from:
class Program
{
static void Main(string[] args)
{
var foo = new Foo();
}
}
I want to get Program uses Foo.
I already parse all documents and get the declared class inside.
// all projects in solution
foreach (var project in _solution.Projects)
{
// all documents inside project
foreach (var document in project.Documents)
{
var syntaxRoot = await document.GetSyntaxRootAsync();
var model = await document.GetSemanticModelAsync();
var classes = syntaxRoot.DescendantNodes().OfType<ClassDeclarationSyntax>();
// all classes inside document
foreach (var classDeclarationSyntax in classes)
{
var symbol = model.GetDeclaredSymbol(classDeclarationSyntax);
var objectCreationExpressionSyntaxs = classDeclarationSyntax.DescendantNodes().OfType<ObjectCreationExpressionSyntax>();
// all object creations inside document
foreach (var objectCreationExpressionSyntax in objectCreationExpressionSyntaxs)
{
// TODO: Get the identifier value
}
}
}
}
The problem is to get the IdentifierName Foo. Using the debugger, I see objectCreationExpressionSyntax.Typegot the Identifier.Text got the value I need, but objectCreationExpressionSyntax.Type.Identifierseems to be private.
I could use the SymbolFinder to find all references of a Class in the solution. As I already need to parse all documents its should work without.
Maybe I am on the wrong path? How to get the identifier value?
You'll need to handle the different types of TypeSyntaxes. See here: http://sourceroslyn.io/#Microsoft.CodeAnalysis.CSharp/Syntax/TypeSyntax.cs,29171ac4ad60a546,references
What you see in the debugger is a SimpleNameSyntax, which does have a public Identifier property.
Update
var ns = objectCreationExpressionSyntax.Type as NameSyntax;
if (ns != null)
{
return ns.Identifier.ToString();
}
var pts = objectCreationExpressionSyntax.Type as PredefinedTypeSyntax;
if (pts != null)
{
return pts.Keyword.ToString();
}
...
All other subtypes would need to be handed. Note that ArrayType.ElementType is also a TypeSyntax, so you would most probably need to make this method recursive.
You can get the identifier from the syntax's Type property:
foreach (var objectCreationExpressionSyntax in objectCreationExpressionSyntaxs)
{
IdentifierNameSyntax ins = (IdentifierNameSyntax)objectCreationExpressionSyntax.Type;
var id = ins.Identifier;
Console.WriteLine(id.ValueText);
}
Strings can be misleading.
Let's say you have the expression new SomeClass(), and you get the string "SomeClass" out of it. How do you know if that refers to Namespace1.SomeClass or Namespace2.SomeClass ? What if there is a using SomeClass = Namespace3.SomeOtherType; declaration being used?
Fortunately, you don't have to do this analysis yourself. The compiler can bind the ObjectCreationExpressionSyntax to a symbol. You have your semantic model, use it.
foreach (var oce in objectCreationExpressionSyntaxs)
{
ITypeSymbol typeSymbol = model.GetTypeInfo(oce).Type;
// ...
}
You can compare this symbol with the symbols you get from model.GetDeclaredSymbol(classDeclarationSyntax), just make sure you use the Equals method, not the == operator.
I a bunch of C# Files that I want to migrate to a new version of an internal framework we use for development. So far I have been able to accomplish certain things But there is a particular method invocation that i have to modify to use await modifier and the method calls come in different flavors like so
var a = EntityService.GetBy(Entities.INSTANT_ISSUANCE_REQUEST, requestFilter);
var b = EntityService.GetBy(Entities.ISSUANCE_SETTINGS, new DejaVuObject()).FirstOrDefault();
I have to modify the above method calls so that they use the following syntax
var a = await EntityService.GetBy(Entities.INSTANT_ISSUANCE_REQUEST, requestFilter);
var b = await EntityService.GetBy(Entities.ISSUANCE_SETTINGS, new DejaVuObject()).FirstOrDefault();
I am using Roslyn CSharpSyntaxWriter to traverse the syntax tree.
public override SyntaxNode VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node)
{
var variableDeclarations =
from i in node.DescendantNodes().OfType<VariableDeclaratorSyntax>()
where i.DescendantNodes().OfType<EqualsValueClauseSyntax>().Any<EqualsValueClauseSyntax>(
p => p.DescendantNodes().OfType<InvocationExpressionSyntax>().Any<InvocationExpressionSyntax>())
select i;
foreach (var syntax in variableDeclarations)
{
var equalsToken = syntax.DescendantNodes();
//now we have the equals token
foreach (var syntaxNode in equalsToken)
{
if (syntaxNode is EqualsValueClauseSyntax)
{
var equalsValueSyntax = syntaxNode.DescendantNodes().OfType<InvocationExpressionSyntax>();
foreach (var invocationExpressionSyntax in equalsValueSyntax)
{
var simpleMemberAcessExpressions = invocationExpressionSyntax
.DescendantNodes()
.OfType<IdentifierNameSyntax>()
.Where(i => i.Identifier.Text == "EntityService");
foreach (var simpleMemberAcessExpression in simpleMemberAcessExpressions)
{
var newExpression = $"{invocationExpressionSyntax.ToFullString()}";
Console.WriteLine(newExpression);
//TODO: Modify the Node
}
}
}
}
}
return base.VisitLocalDeclarationStatement(node);
}
My problem here is the output in Console is somewhat duplicative
EntityService.GetBy(Entities.ISSUANCE_SETTINGS, new DejaVuObject()).FirstOrDefault();
EntityService.GetBy(Entities.ISSUANCE_SETTINGS, new DejaVuObject())
Both refer to same InvocationExpression but because of the FirstOrDefault() it shows up twice in the console output
I would like for a way to filter the results so that they contain only unique Method Invocations and perform the actual modification of the method call by adding the await modifier and updating the node.
first of all, why override VisitLocalDeclarationStatement? Looks like you should be overriding VisitInvocationExpression.
You shouldn't be doing this:
var simpleMemberAcessExpressions =
invocationExpressionSyntax.DescendantNodes().OfType<IdentifierNameSyntax>()
Instead, it should be something like:
var identifier =
(node.Expression as MemberAccessExpressionSyntax)?.Expression as IdentifierNameSyntax;
if (identifier != null && identifier.Identifier.Text == "EntityService")
{
// process the invocation expression
}
Assuming the invocation expression is called node, your new expression is probably
var newExpression =
SyntaxFactory.ParenthesizedExpression(SyntaxFactory.AwaitExpression(node))
.WithAdditionalAnnotations(Simplifier.Annotation)
.WithAdditionalAnnotations(Formatter.Annotation);
I try to make code completion with Roslyn and AvalonEdit.
For example, user have code:
public void Completion(int i,int j) { }
And he types:
Completion(
So, i want to get arguments of method (int i, int j) and make code completion.
I write simple code, wich works with '.' and may be this code will work for '(' letter?
public List<ICompletionData> GetCompletionData(String code,int offset,CompletionType completionType)
{
var syntaxTree = SyntaxFactory.ParseSyntaxTree(code);
var compilation = CSharpCompilation.Create("foo")
.AddReferences(Mscorlib)
.AddSyntaxTrees(syntaxTree);
var semanticModel = compilation.GetSemanticModel(syntaxTree);
var textSpan = GetTextSpan(offset,1);// '.' or '(' coordinates
ITypeSymbol lhsType = null;
if (completionType == CompletionType.DotCompletion)
{
var memberAccessNode = (MemberAccessExpressionSyntax)syntaxTree.GetRoot()
.DescendantNodes(textSpan).Last();
lhsType = semanticModel.GetTypeInfo(memberAccessNode.Expression).Type;
}
else if(completionType==CompletionType.ArgumentListCompletion)
{
var arr = syntaxTree.GetRoot().DescendantNodes(textSpan).Last();
var argumentListMode = (ArgumentListSyntax)syntaxTree.GetRoot().DescendantNodes(textSpan).Last();
var directive = argumentListMode.GetFirstDirective();
var arrgs=argumentListMode.Arguments;
//lhsType = semanticModel.GetTypeInfo(directive).Type;
//how to get lhsType?
}
if (lhsType == null)
return new List<ICompletionData>();
List<ICompletionData> completionDataColl = new List<ICompletionData>();
// and here i make completion data
foreach (var symbol in lhsType.GetMembers())
{
if (!symbol.CanBeReferencedByName
|| symbol.DeclaredAccessibility != Accessibility.Public
|| symbol.IsStatic)
continue;
}
}
The problem is, that i can not get ITypeSymbol lhsType. It is null.
How to get lhsType?
Or, maybe i should use another way?
I don't know the code completion (I couldn't find this class called CompletionType) itself, but here is a way based on Roslyn only: semantic model and the method invocation, which I believe you have available (make the method call string a InvocationExpressionSyntax)
To obtain the arguments of a method you can get its SymbolInfo from the semantic model. Then you get its symbol. A symbol contains the list of parameters(arguments).
You can call SemanticModel.GetSymbolInfo()
The result will provide you a symbol or candidate symbols (if it is an overloaded method).
A method symbol will provide the list of parameters, which is the arguments of that method.