using Microsoft.CodeAnalysis.Text; SourceText source = SourceText.From("Hello World!"); string text = source.ToString(); // Output: "Hello World!"
using Microsoft.CodeAnalysis.Text; using System.Text; Encoding encoding = Encoding.UTF8; string helloWorld = "Hello World!"; byte[] sourceBytes = encoding.GetBytes(helloWorld); SourceText source = SourceText.From(sourceBytes, sourceBytes.Length); string text = source.ToString(encoding); // Output: "Hello World!"In the code examples above, we are creating a `SourceText` instance using `SourceText.From()` method, which takes a string or a byte array as a parameter. We then call `ToString()` method on the `SourceText` instance to convert it to a string. In the second example, we also specify the encoding to be used for the conversion. To use `Microsoft.CodeAnalysis.Text`, you need to install the `Microsoft.CodeAnalysis.Common` package, which contains the base types used by all Roslyn features.