문제

Can somebody familiar with microsoft robotics studio please explain why the handler operations are virtual and some are set as non-virtual ?

[ServiceHandler(ServiceHandlerBehavior.Concurrent)]
public virtual IEnumerator<ITask> GetHandler(Get get)
{
    get.ResponsePort.Post(_state);
    yield break;
}

vs

[ServiceHandler(ServiceHandlerBehavior.Concurrent)]
public IEnumerator<ITask> SubscribeHandler(Subscribe subscribe)
{
    SubscribeRequestType request = subscribe.Body;
    LogInfo("Subscribe request from: " + request.Subscriber);

    // Use the Subscription Manager to handle the subscribers
    yield return Arbiter.Choice(
        SubscribeHelper(_submgrPort, request, subscribe.ResponsePort),
        delegate(SuccessResult success)
        {
            // Send a notification on successful subscription so that the
            // subscriber can initialize its own state
            base.SendNotificationToTarget<Replace>(request.Subscriber, _submgrPort, _state);
        },
        delegate(Exception e)
        {
            LogError(null, "Subscribe failed", e);
        }
    );

    yield break;
}

Thanks in advance.

도움이 되었습니까?

해결책

Virtual handlers are used in classes you expect to use as base for other classes. Handlers that are not virtual are either declared as overrides in derived classes, or in classes that will not be derived (as is often the case in sample code).

Refer to the following articles:

http://msdn.microsoft.com/en-us/library/9fkccyh4(v=VS.100).aspx

What are Virtual Methods?

C# virtual methods question

WHy should virtual methods be explicitly overridden in C#?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top