← Atrás

Создание уникального правила у стратегии

У меня имеется класс ImportantQuotes, в котором есть несколько Event'ов. Мне необходимо написать правило для стратегии, что при возникновении события у ImportantQuotes выполнялся какой-нибудь метод. Написал по образу и подобию из мануала StrategyRule:


private sealed class BigButtAppearedRule : StrategyRule
        {

            public BigButtAppearedRule(Strategy strategy)
            {
                if (strategy == null)
                    throw new ArgumentNullException("strategy");

                this.Strategy = strategy;
                ExtendedGlassWindow.Instance._ImportantQuote.BigButtAppeared += OnStrategyActive;
            }

            private new Strategy Strategy { get; set; }

            private void OnStrategyActive()
            {
                base.Activate();
            }

            protected override void DisposeManaged()
            {
                ExtendedGlassWindow.Instance._ImportantQuote.BigButtAppeared -= OnStrategyActive;
                base.DisposeManaged();
            }
        }

Подскажите пожалуйста, как это вообще присоединить к стратегии и привести к виду .when(мое событие) .do(метод)

¿Le resultó útil este tema?

Compartir tema

Comentarios (1)

Iniciar sesión o Crear cuenta, Inicie sesión o regístrese para dejar un comentario

esper
esper

Делаем extension метод

public static StrategyRule BigButtAppeared(this Strategy strategy)
{
    if (strategy == null)
        throw new ArgumentNullException("strategy");

    return new BigButtAppearedRule(strategy);
}

а далее как обычно


this.Wneh(this.BigButtAppeared()).Do()
Dottz