← Zurück

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

У меня имеется класс 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(метод)

War dieses Thema hilfreich?

Thema teilen

Kommentare (1)

Anmelden oder Konto erstellen, Melden Sie sich an oder registrieren Sie sich, um einen Kommentar zu hinterlassen

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