private static LocalContextToken PrepareLocalContext(Type type)
        {
            var token = new LocalContextToken
            {
                Type              = type,
                OldContext        = LocalContext.Value,
                ClearLocalContext = false
            };

            if (typeof(AssetComposite).IsAssignableFrom(token.Type))
            {
                // Entering the asset root node, create the local context.
                LocalContext.Value      = new AssetCompositeVisitorContext(token.Type);
                token.ClearLocalContext = true;
            }
            else if (LocalContext.Value == null && AssetRegistry.IsAssetPartType(token.Type))
            {
                var attributes = AssetRegistry.GetPartReferenceAttributes(token.Type);
                LocalContext.Value      = new AssetCompositeVisitorContext(attributes);
                token.ClearLocalContext = true;
            }

            token.RemoveLastEnteredNode = LocalContext.Value?.EnterNode(token.Type) ?? false;
            return(token);
        }
        private static void CleanLocalContext(LocalContextToken token)
        {
            LocalContext.Value?.LeaveNode(token.RemoveLastEnteredNode);

            if (token.ClearLocalContext)
            {
                // Exiting the asset root node, clear the local context.
                LocalContext.Value = token.OldContext;
            }
        }
        private static void CleanLocalContext(LocalContextToken token)
        {
            LocalContext.Value?.LeaveNode(token.Type, token.RemoveLastEnteredType);

            if (token.ClearLocalContext)
            {
                // Exiting the asset root node, clear the local context.
                LocalContext.Value = token.OldContext;
            }
        }
        private static LocalContextToken PrepareLocalContext(Type type)
        {
            var token = new LocalContextToken
            {
                Type = type,
                OldContext = LocalContext.Value,
                ClearLocalContext = false
            };

            if (typeof(AssetComposite).IsAssignableFrom(token.Type))
            {
                // Entering the asset root node, create the local context.
                LocalContext.Value = new AssetCompositeVisitorContext(token.Type);
                token.ClearLocalContext = true;
            }
            else if (LocalContext.Value == null && AssetRegistry.IsAssetPartType(token.Type))
            {
                var attributes = AssetRegistry.GetPartReferenceAttributes(token.Type);
                LocalContext.Value = new AssetCompositeVisitorContext(attributes);
                token.ClearLocalContext = true;
            }

            token.RemoveLastEnteredType = LocalContext.Value?.EnterNode(token.Type) ?? false;
            return token;
        }