Attaching elements
Step 5 - Adding Children to Root Element
When adding children to our root element, like with our root element, we need to have security in place. This time we will use native parents instead of the hooking method. We start out by creating a new entity token type:
[SecurityAncestorProvider(typeof(MySecurityAncestorProvider))] public sealed class MyEntityToken : EntityToken { public MyEntityToken(string publicationStatus) { this.PublicationStatus = publicationStatus; } public string PublicationStatus { get; set; } public override string Type { get { return ""; } } public override string Source { get { return ""; } } public override string Id { get { return this.PublicationStatus; } } public override string Serialize() { return DoSerialize(); } public static EntityToken Deserialize(string serializedEntityToken) { string type, source, id; DoDeserialize(serializedEntityToken, out type, out source, out id); return new MyEntityToken(id); } }
This class looks almost like our MyRootEntityToken class with two differences, though. The first one is that we have changed the NoAncestorSecurityAncestorProvider to our own SecurityAncestorProvider: MySecurityAncestorProvider. The second one is that this entity token holds a value: publicationStatus. We will use this value later on. It is important to note that some extra care in de-serialization has to be taken.