public override Dd4tComponentPresentation BuildComponentPresentation(TcmComponentPresentation tcmComponentPresentation, Engine engine,
     int linkLevels, bool resolveWidthAndHeight)
 {
     Dd4tComponentPresentation result = base.BuildComponentPresentation(tcmComponentPresentation, engine, linkLevels, resolveWidthAndHeight);
     AddCpExtensionData(result, tcmComponentPresentation);
     return result;
 }
        private void AddCpExtensionData(Dd4tComponentPresentation dd4tComponentPresentation, TcmComponentPresentation tcmComponentPresentation)
        {
            if (!tcmComponentPresentation.Conditions.Any())
            {
                return;
            }
            _logger.Debug("ComponentPresentation has Conditions");

            string[] includeContextExpressions = ContextExpressionManager.GetContextExpressions(tcmComponentPresentation.Conditions.Where(c => !c.Negate).Select(c => c.TargetGroup));
            string[] excludeContextExpressions = ContextExpressionManager.GetContextExpressions(tcmComponentPresentation.Conditions.Where(c => c.Negate).Select(c => c.TargetGroup));

            if (includeContextExpressions.Any())
            {
                _logger.Debug("Adding Context Expression Conditions (Include): " + string.Join(", ", includeContextExpressions));
                dd4tComponentPresentation.AddExtensionProperty(ContextExpressionSectionName, "Include", includeContextExpressions);
            }

            if (excludeContextExpressions.Any())
            {
                _logger.Debug("Adding Context Expression Conditions (Exclude): " + string.Join(", ", excludeContextExpressions));
                dd4tComponentPresentation.AddExtensionProperty(ContextExpressionSectionName, "Exclude", excludeContextExpressions);
            }
        }