当前位置: 首页>>代码示例>>C#>>正文


C# Observer类代码示例

本文整理汇总了C#中Observer的典型用法代码示例。如果您正苦于以下问题:C# Observer类的具体用法?C# Observer怎么用?C# Observer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Observer类属于命名空间,在下文中一共展示了Observer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PropertyChanged_should_call_weakly_subscribed_handler_when_handler_is_collected

        public void PropertyChanged_should_call_weakly_subscribed_handler_when_handler_is_collected()
        {
            // Arrange
            var observer = new Observer();
            var model = new SomeModel(observer);
            Action<int> onChange = model.Change;
            var weakOnChange = new WeakReference(onChange);

            var counter = Reactive.Of(0);
            counter.PropertyChanged +=
                (sender, args) =>
                {
                    var handler = weakOnChange.Target as Action<int>;
                    if (handler != null)
                        handler(counter);
                };

            // Act
            onChange = null;
            GC.Collect();
            counter.Value = 1;

            // Assert
            observer.ChangedObserved.Should().BeFalse();
        }
开发者ID:EamonNerbonne,项目名称:FunTools,代码行数:25,代码来源:ReactiveWeakSubscriptionTests.cs

示例2: AddObserver

 /// <summary>
 /// Adds an observer to recieve our notifications.
 /// </summary>
 /// <param name='o'>
 /// An Observer to add.
 /// </param>
 public void AddObserver(Observer o)
 {
     if (!observerList.Contains (o))
     {
         observerList.Add (o);
     }
 }
开发者ID:Jay2645,项目名称:text-adventure,代码行数:13,代码来源:Subject.cs

示例3: RemoveObserver

 public void RemoveObserver(Observer o)
 {
     if (observerList.Contains(o))
     {
         observerList.Remove(o);
     }
 }
开发者ID:Jay2645,项目名称:UnityHelperFunctions,代码行数:7,代码来源:Subject.cs

示例4: Main

  static void Main(){
    IStack stacy = new StackImpl1();
    StackDecorator1 orrico = new StackDecorator1(stacy);
    Observer StackObserver1 = new Observer();
    Observer StackObserver2 = new Observer();
    orrico.attach(StackObserver1);
    orrico.attach(StackObserver2);
    orrico.howMany();
    orrico.pushStack("Stella");
    orrico.pushStack("was");
    orrico.pushStack("a");
    orrico.pushStack("Diver");

    // Sin decorar
    stacy.pushStack("and");
    stacy.pushStack("she");
    stacy.pushStack("was");
    stacy.pushStack("always");
    stacy.pushStack("down");
    // decorar Sin

    orrico.howMany();
    orrico.popStack();
    orrico.howMany();
  }
开发者ID:wally-fork,项目名称:clasecsharp,代码行数:25,代码来源:Stacker.cs

示例5: AjouterObservateur

 public void AjouterObservateur(Observer observer)
 {
     if (!observers.Contains(observer))
     {
         observers.Add(observer);
     }
 }
开发者ID:keylax,项目名称:Exercice_5_-_Introduction_a_XNA,代码行数:7,代码来源:SubjectObserver.cs

示例6: AddObserver

 /// <summary>
 /// Adds the observer.
 /// </summary>
 /// <param name="observer">The observer.</param>
 public void AddObserver(Observer observer)
 {
     if (!observers.Contains(observer))
     {
         observers.Add(observer);
     }
 }
开发者ID:willbur415,项目名称:POO_TP1,代码行数:11,代码来源:ObservedSubject.cs

示例7: AddObserver

 public NSObject AddObserver(string name, Action<NSNotification> action, NSObject fromObject = null)
 {
     var handler = new Observer(action);
     Callbacks.Subscribe(handler, SelectorName, n => action(Runtime.GetNSObject<NSNotification>(n)));
     ObjC.MessageSend(Handle, Selector.GetHandle("addObserver:selector:name:object:"), handler.Handle, Selector.GetHandle(SelectorName), name, fromObject == null ? IntPtr.Zero : fromObject.Handle);
     return handler;
 }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:7,代码来源:NSNotificationCenter.cs

示例8: Init

        public void Init()
        {
            player1Observer = new MockObserver("Player1 Observer");
            fullPlayerObserver = new MockObserver("FullPlayer Observer");
            player1InventoryObserver = new MockObserver("Player 1 Inventory Observer");
            fullPlayerInventoryObserver = new MockObserver("FullPlayer Inventory Observer");

            player1 = new Player ("Player1", Gender.FEMALE, "Eve2", new Vector2 (0, 0));
            player1.AddObserver(player1Observer);

            fullPlayer = new Player ("Ollie", Gender.MALE, "Evan1", Vector2.zero);
            fullPlayer.InitialiseInventory (20);
            fullPlayer.AddObserver(fullPlayerObserver);
            fullPlayer.Inventory.AddObserver(fullPlayerInventoryObserver);

            for (int i = 0; i < 20; i++) {
                InventoryItem item = new InventoryItem();
                item.ItemName = "Item" + i;
                item.ItemId = i;
                item.ItemType = ItemType.RUBBISH;
                item.ItemDescription = string.Empty;
                fullPlayer.AddItem(item);
            }

            tool1 = new MockTool("Tool1");
            tool2 = new MockTool("Tool2");
            tool3 = new MockTool("Tool3");

            fullPlayer.AddTool(tool1);
            fullPlayer.AddTool(tool2);
            fullPlayer.AddTool(tool3);
        }
开发者ID:ocoulson,项目名称:MScProjectUnity,代码行数:32,代码来源:PlayerTest.cs

示例9: Insert

 // inser at begining fo the queue
 public void Insert(Behaviour behaviour, Observer observer)
 {
     if(observer != null){
         behaviour.observer = observer;
     }
     behaviours.Push(behaviour);
 }
开发者ID:Suike,项目名称:Tools,代码行数:8,代码来源:BehaviourTree.cs

示例10: SubscribeObserver

 public void SubscribeObserver(Observer observer)
 {
     if (!_subscribedObservers.Contains(observer))
     {
         _subscribedObservers.Add(observer);
     }
 }
开发者ID:zgredziucha,项目名称:areria,代码行数:7,代码来源:CheckPoint.cs

示例11: RegisterObserver

 public void RegisterObserver(Observer.IObserver o)
 {
     if (o != null)
     {
         observerCollection.Add(o);
     }
 }
开发者ID:dmoelgaard,项目名称:design-patterns-simple,代码行数:7,代码来源:Subject.cs

示例12: UnregisterObserver

 public void UnregisterObserver(Observer.IObserver o)
 {
     if (o != null)
     {
         observerCollection.Remove(o);
     }
 }
开发者ID:dmoelgaard,项目名称:design-patterns-simple,代码行数:7,代码来源:Subject.cs

示例13: Demo

 static void Demo()
 {
     Subject subject = new Subject();
     Observer Observer = new Observer(subject, "Center", "\t\t");
     Observer observer2 = new Observer(subject, "Right", "\t\t\t\t");
     subject.Go();
 }
开发者ID:aloneplayer,项目名称:BenProjects,代码行数:7,代码来源:EventDemo.cs

示例14: Main

 public void Main()
 {
     var subject = new Subject();
     var Observer = new Observer(subject, "Center", "\t\t");
     var observer2 = new Observer(subject, "Right", "\t\t\t\t");
     subject.Go();
 }
开发者ID:david--liu,项目名称:code_kata,代码行数:7,代码来源:ObserverPatternTheory.cs

示例15: FolderManager

 public FolderManager()
 {
     
     InitializeComponent();
     _bobserver = new BObserver();
     _observer = null;
 }
开发者ID:jefridev,项目名称:AFileOrganizer,代码行数:7,代码来源:FolderManager.xaml.cs


注:本文中的Observer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。