Esempio n. 1
0
        public override void VisitUsingDirective(UsingDirectiveSyntax node)
        {
            // these could theoretically be acquired by indexing the GAC or something
            var namespaces = new List <String>
            {
                "System",
                "System.Collections",
                "System.Collections.Generic",
                "System.Text",
                "System.Linq"
            };
            string whatAreWeUsing = node.Name.ToString();

            if (!namespaces.Contains(whatAreWeUsing))
            {
                var parts = whatAreWeUsing.Split('.');
                cb.AppendIndent().Append("using namespace ").Append(string.Join("::", parts)).AppendLine(";");
            }
        }
Esempio n. 2
0
        public override void VisitConstructorDeclaration(ConstructorDeclarationSyntax node)
        {
            cb.AppendIndent()
            .Append(node.Identifier.ToString())
            .Append("::")
            .Append(node.Identifier.ToString())
            .Append("(");

            if (node.ParameterList != null)
            {
                var pars = node.ParameterList.Parameters.ToList();
                for (int i = 0; i < pars.Count; ++i)
                {
                    var p = pars[i];
                    var z = model.GetDeclaredSymbol(p);
                    cb.Append(ArgumentTypeFor(z.Type))
                    .Append(" ")
                    .Append(p.Identifier.Text);
                    if (i + 1 != pars.Count)
                    {
                        cb.Append(", ");
                    }
                }
            }

            cb.Append(")");

            var parent = node.Parent as ClassDeclarationSyntax;

            if (parent != null && parent.HasInitializableMembers(model))
            {
                cb.AppendLine(" :");
                cb.Indent(() => AppendFieldInitializers(parent));
            }
            else
            {
                cb.AppendLine();
            }

            cb.AppendLineWithIndent("{");
            cb.Indent(() => base.VisitConstructorDeclaration(node));
            cb.AppendLineWithIndent("}");
        }