コード例 #1
0
        public static ButtonsTemplate ToButtonsTemplate(this IButtonsTemplate self)
        {
            if (self.Text == null)
            {
                throw new InvalidOperationException("The text cannot be null.");
            }

            ButtonsTemplate buttonsTemplate = self as ButtonsTemplate;

            if (buttonsTemplate == null)
            {
                buttonsTemplate = new ButtonsTemplate()
                {
                    ThumbnailUrl = self.ThumbnailUrl,
                    Title        = self.Title,
                    Text         = self.Text,
                };
            }

            if (self.Actions == null)
            {
                throw new InvalidOperationException("The actions cannot be null.");
            }

            buttonsTemplate.Actions = self.Actions.ToTemplateAction().ToArray();

            return(buttonsTemplate);
        }
コード例 #2
0
        internal static ButtonsTemplate Convert(IButtonsTemplate template)
        {
            if (template.Text == null)
            {
                throw new InvalidOperationException("The text cannot be null.");
            }

            if (!(template is ButtonsTemplate buttonsTemplate))
            {
                buttonsTemplate = new ButtonsTemplate()
                {
                    ThumbnailUrl = template.ThumbnailUrl,
                    Title        = template.Title,
                    Text         = template.Text,
                };
            }

            if (template.Actions == null)
            {
                throw new InvalidOperationException("The actions cannot be null.");
            }

            buttonsTemplate.Actions = TemplateAction.Convert(template.Actions);

            return(buttonsTemplate);
        }
コード例 #3
0
        private static ITemplate Convert(ITemplate template)
        {
            switch (template)
            {
            case IButtonsTemplate buttonsTemplate:
                return(ButtonsTemplate.Convert(buttonsTemplate));

            case IConfirmTemplate confirmTemplate:
                return(ConfirmTemplate.Convert(confirmTemplate));

            case ICarouselTemplate carouselTemplate:
                return(CarouselTemplate.Convert(carouselTemplate));

            case IImageCarouselTemplate imageCarouselTemplate:
                return(ImageCarouselTemplate.Convert(imageCarouselTemplate));

            default:
                throw new NotSupportedException("Invalid template type.");
            }
        }