Created
January 1, 2016 18:26
-
-
Save praeclarum/953629b2f80860e54747 to your computer and use it in GitHub Desktop.
My attempt to get Roslyn working on iOS
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; | |
using UIKit; | |
using Microsoft.CodeAnalysis; | |
using System.Linq; | |
using Microsoft.CodeAnalysis.Host; | |
using System.Collections.Generic; | |
namespace RR | |
{ | |
public class TestVC : UITableViewController | |
{ | |
public TestVC () | |
{ | |
try { | |
var baseWS = new AdhocWorkspace (); | |
var ws = new AdhocWorkspace (new NoMefHostServices (baseWS.Services)); | |
var pid = ProjectId.CreateNewId ("PROJ"); | |
ws.AddProject (ProjectInfo.Create (pid, VersionStamp.Default, "Poo", "Poo", LanguageNames.CSharp)); | |
} catch (Exception ex) { | |
Console.WriteLine (ex); | |
} | |
} | |
} | |
class NoMefHostServices : HostServices | |
{ | |
readonly HostWorkspaceServices baseWSServices; | |
public NoMefHostServices (HostWorkspaceServices baseWSServices) | |
{ | |
this.baseWSServices = baseWSServices; | |
} | |
#region implemented abstract members of HostServices | |
protected override HostWorkspaceServices CreateWorkspaceServices (Workspace workspace) | |
{ | |
return new NoMefHostWorkspaceServices (this, workspace, baseWSServices); | |
} | |
#endregion | |
} | |
class NoMefHostWorkspaceServices : HostWorkspaceServices | |
{ | |
readonly HostWorkspaceServices baseWSServices; | |
readonly Workspace workspace; | |
readonly NoMefHostServices hostServices; | |
readonly Dictionary<string, HostLanguageServices> languageServices = new Dictionary<string, HostLanguageServices> (); | |
public NoMefHostWorkspaceServices (NoMefHostServices hostServices, Workspace workspace, HostWorkspaceServices baseWSServices) | |
{ | |
this.hostServices = hostServices; | |
this.workspace = workspace; | |
this.baseWSServices = baseWSServices; | |
} | |
#region implemented abstract members of HostWorkspaceServices | |
public override TWorkspaceService GetService<TWorkspaceService> () | |
{ | |
var t = typeof(TWorkspaceService); | |
Console.WriteLine (t); | |
var r = baseWSServices.GetService<TWorkspaceService> (); | |
return r; | |
} | |
public override System.Collections.Generic.IEnumerable<TLanguageService> FindLanguageServices<TLanguageService> (MetadataFilter filter) | |
{ | |
throw new NotSupportedException (); | |
} | |
public override HostLanguageServices GetLanguageServices (string languageName) | |
{ | |
HostLanguageServices r; | |
if (!languageServices.TryGetValue (languageName, out r)) { | |
r = new NoMefHostLanguageServices (this, languageName); | |
languageServices [languageName] = r; | |
} | |
return r; | |
} | |
public override HostServices HostServices { | |
get { | |
return hostServices; | |
} | |
} | |
public override Workspace Workspace { | |
get { | |
return workspace; | |
} | |
} | |
#endregion | |
} | |
class NoMefHostLanguageServices : HostLanguageServices | |
{ | |
readonly string language; | |
readonly HostWorkspaceServices hostWorkspaceServices; | |
public NoMefHostLanguageServices (HostWorkspaceServices hostWorkspaceServices, string language) | |
{ | |
this.hostWorkspaceServices = hostWorkspaceServices; | |
this.language = language; | |
} | |
#region implemented abstract members of HostLanguageServices | |
public override TLanguageService GetService<TLanguageService> () | |
{ | |
var t = typeof(TLanguageService); //= Microsoft.CodeAnalysis.Host.ICompilationFactoryService | |
Console.WriteLine (t); | |
throw new NotImplementedException (); | |
} | |
public override HostWorkspaceServices WorkspaceServices { | |
get { | |
return hostWorkspaceServices; | |
} | |
} | |
public override string Language { | |
get { | |
return language; | |
} | |
} | |
#endregion | |
} | |
class NoMefCompilationFactoryService : Microsoft.CodeAnalysis.Host.ICompilationFactoryService | |
{ | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment