小编dav*_*ett的帖子

c#泛型类的具体覆盖

这是我正在使用的通用类:

 public interface IRepository<T> where T : EntityObject
{
    RepositoryInstructionResult Add(T item);
    RepositoryInstructionResult Update(T item);
    RepositoryInstructionResult Delete(T item);
}
public class Repository<T> : IRepository<T> where T : EntityObject
{

    RepositoryInstructionResult Add(T item)
    { //implementation}
    RepositoryInstructionResult Update(T item);
    { //implementation}
    RepositoryInstructionResult Delete(T item);
    { //implementation}
 }
Run Code Online (Sandbox Code Playgroud)

现在我想在t:特定类型时偶尔改变方法的行为.是否有类似以下内容?此特定尝试会产生错误(错误5:"存储库"的部分声明必须具有相同顺序的相同类型参数名称).

public class Repository<Bar> //where Bar : EntityObject
{
    RepositoryInstructionResult Add(Bar item)
    { //different implementation to Repository<T>.Add() }
    //other methods inherit from Repository<T>
 }
Run Code Online (Sandbox Code Playgroud)

.net c# generics inheritance subtype

6
推荐指数
1
解决办法
6835
查看次数

Actor 可以查看 Akka.net 中的 MessageQueue

我有一个 IPClient 演员,它管理/拥有一个打开/关闭成本高昂的连接。

在演员处理完消息之前,我想查看演员邮箱的顶部,检查是否还有另一条消息待处理。- 如果演员还有更多工作,请保持连接打开。- 如果参与者清空了邮箱,则关闭连接。

这是我的想法的要点:

public void Handle(PollDevice message)
    {
        if (!_client.IsConnected)
            _client.Connect();

        var results = _client.GetData()

        var actorHasMoreWork = Context.Dispatcher.Mailboxes.???
        if (!actorHasMoreWork)
            _client.Disconnect();

        Sender.Tell(true);
    }
Run Code Online (Sandbox Code Playgroud)

这可能吗?这是最好的方法吗?

akka.net

5
推荐指数
1
解决办法
853
查看次数

标签 统计

.net ×1

akka.net ×1

c# ×1

generics ×1

inheritance ×1

subtype ×1