I'm finding very little good documentation on Roslyn so forgive me if I missed something and this should be obvious. I'm parsing some code and my aim is to pull out every serializable field from a class.
What I have so far is this. First I parse the code file
SyntaxTree tree = CSharpSyntaxTree.ParseText(programText);
CSharpCompilation compilation = CSharpCompilation.Create("HelloWorld")
.AddReferences(MetadataReference
.CreateFromFile(typeof(object)
.Assembly
.Location))
.AddSyntaxTrees(tree);
CompilationUnitSyntax root = tree.GetCompilationUnitRoot();
Next, I get all the fields from each class
foreach (MemberDeclarationSyntax member in root.Members)
{
if (member is ClassDeclarationSyntax classDeclarationSyntax)
{
foreach (MemberDeclarationSyntax rootGameMember in classDeclarationSyntax.Members)
{
if (IsFieldSerializable(rootGameMember))
{
}
}
}
}
aaaaand now I'm stuck. What I want to do with this field are a few things based on the Unity 3D rules for serialization
- See if the type is public
- See if the attribute [SerializeField] is applied
- See if the type is int, float, string, double etc
- See if the type, if its a class has the [Serializable] attribute
I think that's it. At the moment I'm trying to figure out the type of the field and getting lost in a rabbit warren of options of which none seem to give me what I want.