本文整理汇总了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();
}
示例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);
}
}
示例3: RemoveObserver
public void RemoveObserver(Observer o)
{
if (observerList.Contains(o))
{
observerList.Remove(o);
}
}
示例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();
}
示例5: AjouterObservateur
public void AjouterObservateur(Observer observer)
{
if (!observers.Contains(observer))
{
observers.Add(observer);
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例9: Insert
// inser at begining fo the queue
public void Insert(Behaviour behaviour, Observer observer)
{
if(observer != null){
behaviour.observer = observer;
}
behaviours.Push(behaviour);
}
示例10: SubscribeObserver
public void SubscribeObserver(Observer observer)
{
if (!_subscribedObservers.Contains(observer))
{
_subscribedObservers.Add(observer);
}
}
示例11: RegisterObserver
public void RegisterObserver(Observer.IObserver o)
{
if (o != null)
{
observerCollection.Add(o);
}
}
示例12: UnregisterObserver
public void UnregisterObserver(Observer.IObserver o)
{
if (o != null)
{
observerCollection.Remove(o);
}
}
示例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();
}
示例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();
}
示例15: FolderManager
public FolderManager()
{
InitializeComponent();
_bobserver = new BObserver();
_observer = null;
}