Skip to content

Instantly share code, notes, and snippets.

@attilah
Created December 13, 2015 21:41
Show Gist options
  • Save attilah/42a8f62ce28fe83bd770 to your computer and use it in GitHub Desktop.
Save attilah/42a8f62ce28fe83bd770 to your computer and use it in GitHub Desktop.
Roslyn Orleans Codegen
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MetaOrleans
{
class Program
{
static void Main(string[] args)
{
var assemblies = new[]
{
@"Chirper.GrainInterfaces.dll",
@"Chirper.Grains.dll"
};
var metadataReferences = new List<MetadataReference>();
foreach (var assembly in assemblies)
{
metadataReferences.Add(MetadataReference.CreateFromFile(assembly));
}
var compilation = CSharpCompilation.Create("dummy", references: metadataReferences);
var visitor = new GrainVisitor();
visitor.Visit(compilation.GlobalNamespace);
}
private class GrainVisitor : SymbolVisitor
{
public override void VisitNamespace(INamespaceSymbol symbol)
{
Console.WriteLine(symbol.ToDisplayString());
Parallel.ForEach(symbol.GetMembers(), s => Visit(s));
}
public override void VisitNamedType(INamedTypeSymbol symbol)
{
if (symbol.TypeKind == TypeKind.Class)
return;
if (symbol.TypeKind==TypeKind.Interface && (symbol.Name == "IGrainObserver" || symbol.Name == "IAddressable" || symbol.Name == "IGrainExtension"))
return;
if (symbol.TypeKind == TypeKind.Interface && (symbol.Name == "IGrain" || symbol.Name == "IGrainWithGuidKey" || symbol.Name == "IGrainWithIntegerKey"
|| symbol.Name == "IGrainWithGuidCompoundKey" || symbol.Name == "IGrainWithIntegerCompoundKey"))
return;
if (symbol.TypeKind == TypeKind.Interface && symbol.Name=="ISystemTarget")
return;
if (symbol.AllInterfaces.Any(i => i.Name=="IAddressable"))
Console.WriteLine($" {symbol.ToDisplayString()}");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment