Esempio n. 1
0
        public ExpressionSyntax GetObjectCreationExpression(IFrameworkSet frameworkSet)
        {
            if (frameworkSet == null)
            {
                throw new ArgumentNullException(nameof(frameworkSet));
            }

            var targetConstructor = Constructors.OrderByDescending(x => x.Parameters.Count).FirstOrDefault();

            var objectCreation = SyntaxFactory.ObjectCreationExpression(TypeSyntax);

            if (targetConstructor != null && targetConstructor.Parameters.Count > 0)
            {
                return(objectCreation.WithArgumentList(Generate.Arguments(targetConstructor.Parameters.Select(x => SyntaxFactory.IdentifierName(GetConstructorParameterFieldName(x))))));
            }

            if (targetConstructor != null || !Declaration.ChildNodes().OfType <ConstructorDeclarationSyntax>().Any())
            {
                return(objectCreation.WithArgumentList(SyntaxFactory.ArgumentList()));
            }

            return(AssignmentValueHelper.GetDefaultAssignmentValue(TypeSymbol, SemanticModel, frameworkSet));
        }