public override void VisitVariableDeclaration(VariableDeclarationSyntax node) { var fieldInfo = node.Parent as FieldDeclarationSyntax; var modifiers = fieldInfo.Modifiers; bool bPublic = modifiers.Any(c => c.Kind == SyntaxKind.PublicKeyword); string initValue = DefaultValueEmitter.FromType(node.Type.GetText().ToString()); foreach (var variable in node.Variables) { var nodeName = variable.Identifier.ValueText.ToLowerCamelCase(); if (variable.Initializer != null) { initValue = EmitExpression(variable.Initializer.Value); } //base.VisitVariableDeclaration(node); if (bPublic) { _publicCode.WriteLine(" {0}: {1},", nodeName, initValue); } else { _writer.WriteLine(" var {0} = {1};", nodeName, initValue); } } //base.VisitVariableDeclaration(node); }
public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node) { var modifiers = node.Modifiers; bool bPublic = modifiers.Any(c => c.Kind == SyntaxKind.PublicKeyword); /* * bool bGet = false; * bool bSet = false; * * foreach (var acc in node.AccessorList.Accessors) * { * if (acc.Keyword.Kind == SyntaxKind.GetKeyword) * { * bGet = true; * } * if (acc.Keyword.Kind == SyntaxKind.SetKeyword) * { * bSet = true; * } * } */ string nodeName = node.Identifier.ValueText.ToLowerCamelCase(); string initValue = DefaultValueEmitter.FromType(node.Type.GetText().ToString()); if (bPublic) { _publicCode.WriteLine(" {0}: {1},", nodeName, initValue); } else { _writer.WriteLine(" var {0} = {1};", nodeName, initValue); } base.VisitPropertyDeclaration(node); }