Ejemplo n.º 1
0
        // what was Syntax once is now SyntaxFactory
        /// <summary>
        /// Figures the usings and inserts them in the syntax tree.
        /// </summary>
        /// <param name="presentUsings">The usings already found in the source (have to be valid C#).</param>
        /// <param name="optionalUsingsToAdd">All usings that need to be added.</param>
        private static void _GetUsing(SyntaxList<UsingDirectiveSyntax> presentUsings, List<string> optionalUsingsToAdd = null)
        {
            var tmp = presentUsings.ToList();
            var tmpList = new List<string>();

            if (optionalUsingsToAdd != null && optionalUsingsToAdd.Any())
            {
                foreach (var item in optionalUsingsToAdd)
                {
                    foreach (var syntax in tmp)
                    {
                        if (syntax.Name.GetText().ToString() == item)
                        {
                            tmpList.Add(item);
                        }
                    }
                }
                foreach (var item in tmpList)
                {
                    tmp.RemoveAll(x => x.Name.GetText().ToString() == item);
                }
            }

            foreach (var usn in optionalUsingsToAdd)
            {
                NameSyntax name = SyntaxFactory.IdentifierName(usn);
                // to do: modify the tree and add the new usings
            }
        }