This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void TestRoslynCompilation() | |
| { | |
| Compilation compilation = GetSimpleCompilation(); | |
| ImmutableArray<Diagnostic> diagnostics = Compile(compilation); | |
| ShowDiagnostics(diagnostics); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string name = "JOY"; | |
| if(name.Any(char.IsLower)) | |
| { | |
| Console.WriteLine("Word '{0}' has lower letter(s)",name); | |
| } | |
| else | |
| { | |
| Console.WriteLine("Word '{0}' does not have lower letters",name); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Web.Http; | |
| public class MyWebAPIController : ApiController | |
| { | |
| [AcceptVerbs("GET")] | |
| public string Help() | |
| { | |
| return "This is test WEB API. Supported methods are ../api/MyWebAPI/Help, ../api/MyWebAPI/Square/{number}"; | |
| } | |
| [AcceptVerbs("GET")] | |
| public int Square(int id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Web.Http; | |
| using System.Web.Http.SelfHost; | |
| public class WebAPI_HttpSelfHostServer_Test | |
| { | |
| /// <summary> | |
| /// Exposed to outside to starts the server. | |
| /// </summary> | |
| /// <remarks>Simple function call into server class.start method</remarks> | |
| public void StartServer() | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class WebAPI_OWINSelfHostServer_Test | |
| { | |
| /// <summary> | |
| /// Exposed to starts server using WebApp class which uses OWIN specs. | |
| /// </summary> | |
| public void StartServer() | |
| { | |
| WebApp.Start<MyOWINServer>("http://localhost:8080"); | |
| Console.WriteLine("OWIN - Press Enter to quit..."); | |
| Console.ReadLine(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private Compilation GetSimpleCompilation() | |
| { | |
| string source = GetSourceCode(); | |
| SyntaxTree tree = GetSyntaxTree(source); | |
| IEnumerable<MetadataReference> referecnes = GetReferences(); | |
| return CSharpCompilation.Create("TestRoslynOutput", | |
| syntaxTrees: new[] { tree }, | |
| references: referecnes, | |
| options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private string GetSourceCode() | |
| { | |
| return @" | |
| using System; | |
| namespace RoslynCompileSample | |
| { | |
| public class writer | |
| { | |
| public void Write(string message) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private SyntaxTree GetSyntaxTree(string source) | |
| { | |
| SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(source); | |
| return syntaxTree; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private IEnumerable<MetadataReference> GetReferences() | |
| { | |
| return new MetadataReference[] | |
| { | |
| MetadataReference.CreateFromFile(typeof(object).Assembly.Location), | |
| }; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private ImmutableArray<Diagnostic> Compile(Compilation compilation) | |
| { | |
| string outputDllFilePathName = GetOutputFilePath(); | |
| EmitResult result = compilation.Emit(outputDllFilePathName); | |
| Console.WriteLine(" Compilation result = {0}", result.Success); | |
| return result.Diagnostics; | |
| } |
OlderNewer