Ejemplo n.º 1
0
        public static IEnumerable <ISymbol> CreateFieldDelegatingConstructor(
            this ISyntaxFactoryService factory,
            string typeName,
            INamedTypeSymbol containingTypeOpt,
            IList <IParameterSymbol> parameters,
            IDictionary <string, ISymbol> parameterToExistingFieldMap,
            IDictionary <string, string> parameterToNewFieldMap,
            CancellationToken cancellationToken)
        {
            var fields     = factory.CreateFieldsForParameters(parameters, parameterToNewFieldMap);
            var statements = factory.CreateAssignmentStatements(parameters, parameterToExistingFieldMap, parameterToNewFieldMap)
                             .Select(s => s.WithAdditionalAnnotations(Simplifier.Annotation));

            foreach (var field in fields)
            {
                yield return(field);
            }

            yield return(CodeGenerationSymbolFactory.CreateConstructorSymbol(
                             attributes: null,
                             accessibility: Accessibility.Public,
                             modifiers: new SymbolModifiers(),
                             typeName: typeName,
                             parameters: parameters,
                             statements: statements.ToList(),
                             thisConstructorArguments: GetThisConstructorArguments(containingTypeOpt, parameterToExistingFieldMap)));
        }