• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Observer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: RemoveObserver

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


示例17: AddObserver

	public static void AddObserver( Observer newObserver ) {
		if( !listOfObservers.Contains( newObserver ) ) {
		    listOfObservers.Add( newObserver );
		} else {
			Debug.LogWarning( "List already contains " 
			                  + newObserver.ToString( ) );
		}
	}
开发者ID:herman-rogers,项目名称:Relic,代码行数:8,代码来源:Subject.cs


示例18: RemoveObserver

	public static void RemoveObserver( Observer oldObserver ) {
		if( listOfObservers.Contains( oldObserver ) ) {
		    listOfObservers.Remove( oldObserver );
		} else {
			Debug.LogWarning( "No observer named "
			                  + oldObserver.ToString( ) );
		}
	}
开发者ID:herman-rogers,项目名称:Relic,代码行数:8,代码来源:Subject.cs


示例19: Form1

 public Form1()
 {
     InitializeComponent();
     bicycle = new BicycleMointor();
     observer = new Observer(lblRPM, bicycle);
     cph = new CPHObserver(lblCPH, bicycle);
     kph = new KPHObserver(lblKPH, bicycle);
 }
开发者ID:lifengdai,项目名称:IN710dail3,代码行数:8,代码来源:Form1.cs


示例20: addObserver

 public void addObserver(Observer o)
 {
     if (observers.Contains(o))
     {
         return;
     }
     observers.Add(o);
 }
开发者ID:pennetti,项目名称:csharp-heroes,代码行数:8,代码来源:Observable.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Occurrence类代码示例发布时间:2022-05-24
下一篇:
C# ObservableList类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap