This project is read-only.

Please unseal Microsoft.CodeAnalysis.SyntaxAnnotation

Topics: APIs
Apr 4, 2014 at 3:02 PM
Why did you seal it?
Apr 4, 2014 at 3:34 PM
What are u trying to achieve with derived annotation?
Apr 4, 2014 at 3:47 PM
hi heejaechang,
Because I want to store complex data in SyntaxAnnotation:
class MySyntaxAnnotation : SyntaxAnnotation { 
    int a;
    string b;
    SomeClass c;
    ...
}
Apr 4, 2014 at 3:49 PM
One benefit of it being sealed is we can be sure that syntax tree can be serialized and deserialized any time we want without worrying about one of annotations throwing exception due to some custom serialization issue. Also it could have a better serialization perf by not allowing .net serialization.
Apr 4, 2014 at 3:52 PM
Ya, that is basically why we made it sealed so that we can prevent people from doing it. You should maintain a map yourself. (annotation 2 data map)
Apr 6, 2014 at 7:14 PM
That's interesting; why did you count with the serialization scenario? Do you have several AppDomains or processes?
Apr 6, 2014 at 10:01 PM
simple answer.

syntax node supports SerializeTo and DeserializeFrom stream. and we want it to just work and fast.

http://source.roslyn.codeplex.com/#Microsoft.CodeAnalysis/Syntax/SyntaxNode.cs#e13522bb4316ba61
  • but currently, we don't support serializing it in one process/appDomain and deserializing from other process/appDomain. it must be within same app domain.
...

longer answer.

if you start from Workspace with WellKnown feature set,

Workspaces
http://source.roslyn.codeplex.com/#Microsoft.CodeAnalysis.Workspaces/Workspace/CustomWorkspace.cs#c6ee4d431bac2ec7#references
http://source.roslyn.codeplex.com/#Microsoft.CodeAnalysis.Workspaces/Workspace/MSBuild/MSBuildWorkspace.cs#082db07ce1052218#references

WellKnown Feature Set
http://source.roslyn.codeplex.com/#Microsoft.CodeAnalysis.Workspaces/Workspace/WellKnownFeatures.cs#b8358ddff2084c46

we will internally use syntax tree cache that makes sure we don't hold onto every syntax trees in the solution in memory.
http://source.roslyn.codeplex.com/#Microsoft.CodeAnalysis.Workspaces/Workspace/Host/Caching/ISyntaxTreeCacheService.cs#c7dd59ac0f69a53e#references

we use various approaches to achieve this. and one of them is serializing and de-serializing the tree. and we want it to be reliable regardless whether a tree contains an annotation or not.
Marked as answer by TomasMatousek on 4/18/2014 at 9:04 PM