private MemberDeclarationSyntax CreateProperty(VariableDeclarationSyntax node) { var type = semanticModel.GetTypeInfo(node.DescendantNodes().OfType <IdentifierNameSyntax>().FirstOrDefault()); var propertyName = node.DescendantNodes().OfType <IdentifierNameSyntax>().LastOrDefault().Identifier.ValueText; return(CodeElementFactory.CreateProperty(CodeElementFactory.CreateType(type), propertyName)); }
private MemberDeclarationSyntax CreateConstructor(VariableDeclarationSyntax node) { var objectCreationExpression = node.DescendantNodes().OfType <ObjectCreationExpressionSyntax>().FirstOrDefault(); var className = objectCreationExpression.DescendantNodes().OfType <IdentifierNameSyntax>().FirstOrDefault().Identifier.ValueText; return(CodeElementFactory.CreateConstructor(className, GetParametersTypesByArguments(objectCreationExpression.ArgumentList))); }
private MemberDeclarationSyntax CreateMethod(VariableDeclarationSyntax node) { var invocationExpression = node.DescendantNodes().OfType <InvocationExpressionSyntax>().FirstOrDefault(); var methodName = invocationExpression.DescendantNodes().OfType <MemberAccessExpressionSyntax>().FirstOrDefault().GetLastToken().ValueText; var parameters = GetParametersTypesByArguments(invocationExpression.ArgumentList); var type = semanticModel.GetTypeInfo(node.DescendantNodes().OfType <IdentifierNameSyntax>().FirstOrDefault()); return(CodeElementFactory.CreareMethodDeclaration(CodeElementFactory.CreateType(type), methodName, parameters)); }
private IEnumerable <TypeSyntax> GetParametersTypesByArguments(ArgumentListSyntax argumentList) { if (argumentList == null || !argumentList.Arguments.Any()) { yield break; } foreach (var argument in argumentList.Arguments) { var typeInfo = semanticModel.GetTypeInfo(argument.Expression); yield return(CodeElementFactory.CreateType(typeInfo)); } }
public override MemberDeclarationSyntax VisitAssignmentExpression(AssignmentExpressionSyntax node) { if (node.Left == null || node.Right == null || node.OperatorToken == null || node.OperatorToken.Kind() != SyntaxKind.EqualsToken) { return(null); } if (node.Left.Kind() != SyntaxKind.SimpleMemberAccessExpression) { return(null); } var simpleMemberAccessExpression = node.Left as MemberAccessExpressionSyntax; var left = simpleMemberAccessExpression.Expression as IdentifierNameSyntax; if (left == null || left.Identifier == null || left.Identifier.Text != localVaribleName) { return(null); } var typeInfo = semanticModel.GetTypeInfo(node.Right); return(CodeElementFactory.CreateProperty(CodeElementFactory.CreateType(typeInfo), simpleMemberAccessExpression.Name.Identifier.Text)); }
public override MemberDeclarationSyntax VisitInvocationExpression(InvocationExpressionSyntax node) { if (node.Expression == null) { return(null); } if (node.Expression.Kind() != SyntaxKind.SimpleMemberAccessExpression) { return(null); } var simpleMemberAccessExpression = node.Expression as MemberAccessExpressionSyntax; var left = simpleMemberAccessExpression.Expression as IdentifierNameSyntax; if (left == null || left.Identifier == null || left.Identifier.Text != localVaribleName) { return(null); } return(CodeElementFactory.CreareMethodDeclaration(CodeElementFactory.CreateType(SyntaxKind.VoidKeyword), simpleMemberAccessExpression.Name.Identifier.Text, GetParametersTypesByArguments(node.ArgumentList) )); }