public static string PrintPrimitiveValue(object value) { TextWriter writer = new StringWriter(); TextWriterTokenWriter tokenWriter = new TextWriterTokenWriter(writer); tokenWriter.WritePrimitiveValue(value); return(writer.ToString()); }
public static string PrintPrimitiveValue(object value) { TextWriter writer = new StringWriter(); TextWriterTokenWriter tokenWriter = new TextWriterTokenWriter(writer); tokenWriter.WritePrimitiveValue(value, CSharpMetadataTextColorProvider.Instance.GetColor(value)); return(writer.ToString()); }
public static TokenWriter CreateWriterThatSetsLocationsInAST(TextWriter writer, string indentation = "\t") { var target = new TextWriterTokenWriter(writer) { IndentationString = indentation }; return(new InsertSpecialsDecorator(new InsertRequiredSpacesDecorator(new InsertMissingTokensDecorator(target, target)))); }
public string Generate(ISymbol symbol) { if (symbol == null) throw new ArgumentNullException("symbol"); StringWriter writer = new StringWriter(); _writer = new TextWriterTokenWriter(writer); _policy = FormattingOptionsFactory.CreateMono(); TypeSystemAstBuilder astBuilder = CreateAstBuilder(); astBuilder.AlwaysUseShortTypeNames = true; AstNode node = astBuilder.ConvertSymbol(symbol); if (symbol is ITypeDefinition) { WriteTypeDeclarationName((ITypeDefinition)symbol, _writer, _policy); } else if (symbol is IMember) { WriteMemberDeclarationName((IMember)symbol, _writer, _policy); } else { _writer.WriteIdentifier(Identifier.Create(symbol.Name)); } if (HasParameters(symbol)) { _writer.WriteToken(symbol.SymbolKind == SymbolKind.Indexer ? Roles.LBracket : Roles.LPar, symbol.SymbolKind == SymbolKind.Indexer ? "[" : "("); IEnumerable<ParameterDeclaration> parameters = new List<ParameterDeclaration>(node.GetChildrenByRole(Roles.Parameter)); if (symbol is IMethod && ((IMethod)symbol).IsExtensionMethod) { parameters = parameters.Skip(1); } WriteCommaSeparatedList(parameters); _writer.WriteToken(symbol.SymbolKind == SymbolKind.Indexer ? Roles.RBracket : Roles.RPar, symbol.SymbolKind == SymbolKind.Indexer ? "]" : ")"); } if (_includePlaceholders) { _writer.WriteToken(Roles.Text, "$0"); } return writer.ToString(); }
public static ILSpyUnresolvedFile Create(DecompiledTypeReference name, AstBuilder builder) { var writer = new StringWriter(); var target = new TextWriterTokenWriter(writer) { IndentationString = "\t" }; var output = new DebugInfoTokenWriterDecorator(TokenWriter.WrapInWriterThatSetsLocationsInAST(target)); builder.RunTransformations(); var syntaxTree = builder.SyntaxTree; syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); syntaxTree.AcceptVisitor(new CSharpOutputVisitor(output, FormattingOptionsFactory.CreateSharpDevelop())); ILSpyUnresolvedFile file = new ILSpyUnresolvedFile(name); var v = new TypeSystemConvertVisitor(file); syntaxTree.AcceptVisitor(v); file.MemberLocations = output.MemberLocations; file.DebugSymbols = output.DebugSymbols; file.output = writer.ToString(); return file; }
public string ConvertSymbol(ISymbol symbol) { var stringWriter = new StringWriter(); var astBuilder = new TypeSystemAstBuilder(); astBuilder.AlwaysUseShortTypeNames = true; AstNode node = astBuilder.ConvertSymbol(symbol); var writer = new TextWriterTokenWriter (stringWriter); var rt = node.GetChildByRole (Roles.Type); if (!rt.IsNull) { rt.AcceptVisitor (new CSharpOutputVisitor (stringWriter, FormattingOptionsFactory.CreateMono())); } IProperty property = symbol as IProperty; if (property != null) { writer.Space (); writer.WriteToken (Roles.LBrace, "{"); writer.Space (); if (property.CanGet) { writer.WriteKeyword (PropertyDeclaration.GetKeywordRole, "get"); writer.WriteToken (Roles.Semicolon, ";"); writer.Space (); } if (property.CanSet) { writer.WriteKeyword (PropertyDeclaration.SetKeywordRole, "set"); writer.WriteToken (Roles.Semicolon, ";"); writer.Space (); } writer.WriteToken (Roles.RBrace, "}"); } return stringWriter.ToString(); }
public static string PrintPrimitiveValue(object value) { TextWriter writer = new StringWriter(); TextWriterTokenWriter tokenWriter = new TextWriterTokenWriter(writer); tokenWriter.WritePrimitiveValue(value); return writer.ToString(); }
public string ConvertConstantValue(object constantValue) { return(TextWriterTokenWriter.PrintPrimitiveValue(constantValue)); }
public string OutputNode (AstNode node) { using (var stringWriter = new System.IO.StringWriter ()) { var formatter = new TextWriterTokenWriter (stringWriter); // formatter.Indentation = indentLevel; stringWriter.NewLine = Document.Editor.EolMarker; var visitor = new CSharpOutputVisitor (formatter, FormattingOptionsFactory.CreateMono ()); node.AcceptVisitor (visitor); return stringWriter.ToString (); } }
void AppendReturnType (StringBuilder result, CodeGenerationOptions options, IType type) { if (type == null) throw new ArgumentNullException ("type"); var implementingType = options.Part; var loc = implementingType.Region.End; var pf = implementingType.UnresolvedFile; var file = pf as CSharpUnresolvedFile; var resolved = type; if (resolved.Kind == TypeKind.Unknown) { result.Append (type.FullName); return; } var def = type.GetDefinition (); if (def != null) { using (var stringWriter = new System.IO.StringWriter ()) { var formatter = new TextWriterTokenWriter (stringWriter); stringWriter.NewLine = EolMarker; var visitor = new CSharpOutputVisitor (formatter, FormattingOptionsFactory.CreateMono ()); var shortType = CreateShortType (def.Compilation, file, loc, resolved); shortType.AcceptVisitor (visitor); var typeString = stringWriter.ToString (); if (typeString.StartsWith ("global::")) typeString = typeString.Substring ("global::".Length); result.Append (typeString); } } else { result.Append (new ICSharpCode.NRefactory.CSharp.CSharpAmbience ().ConvertType (type)); } }
static string OutputNode (MonoDevelop.Ide.Gui.Document doc, AstNode node) { using (var stringWriter = new System.IO.StringWriter ()) { // formatter.Indentation = indentLevel; var formatter = new TextWriterTokenWriter (stringWriter); stringWriter.NewLine = doc.Editor.EolMarker; var visitor = new CSharpOutputVisitor (formatter, doc.GetFormattingOptions ()); node.AcceptVisitor (visitor); return stringWriter.ToString (); } }
public static string PrintPrimitiveValue(object value) { TextWriter writer = new StringWriter(); TextWriterTokenWriter tokenWriter = new TextWriterTokenWriter(writer); tokenWriter.WritePrimitiveValue(value, CSharpMetadataTextColorProvider.Instance.GetColor(value)); return writer.ToString(); }
public static TokenWriter CreateWriterThatSetsLocationsInAST(TextWriter writer, string indentation = "\t") { var target = new TextWriterTokenWriter(writer) { IndentationString = indentation }; return new InsertSpecialsDecorator(new InsertRequiredSpacesDecorator(new InsertMissingTokensDecorator(target, target))); }