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


Создание уникального правила у стратегии
Atom
10/6/2011


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

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(метод)

Tags:


Thanks:


esper

Avatar
Date: 10/6/2011
Reply


Делаем extension метод
Code
public static StrategyRule BigButtAppeared(this Strategy strategy)
{
    if (strategy == null)
        throw new ArgumentNullException("strategy");

    return new BigButtAppearedRule(strategy);
}


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

Code

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


Attach files by dragging & dropping, , or pasting from the clipboard.

loading
clippy