RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

全部问题

Martin Hope
Faraday
Asked: 2025-02-07 18:51:06 +0000 UTC

工厂组织结构

  • 6

产品结构如下(简化):

public class ParentProduct { }

public sealed class ChildProduct1 : ParentProduct { }

public sealed class ChildProduct2 : ParentProduct { }

enum除了这些类型之外,每种类型都有一个。还必须考虑到这一点enum,并且所有ParentProduct继承人都没有直接关系

public enum ProductType
{
    Parent = 1,
    Child1 = 2,
    Child2 = 3,
}

处理程序的结构大致如下:

public interface IProductHandler<T> where T : ParentProduct
{
    public Task Add(T product);
}

public sealed class ParentHandler : IProductHandler<ParentProduct>
{
    public async Task Add(ParentProduct product)
    {
        // ...
    }
}

public sealed class Child1Handler : IProductHandler<ChildProduct1>
{
    public async Task Add(ChildProduct1 product)
    {
        // ...
    }
}

public sealed class Child2Handler : IProductHandler<ChildProduct2>
{
    public async Task Add(ChildProduct2 product)
    {
        // ...
    }
}

现在需要创建一个工厂ProductType来生产相应的处理程序。但在这个特定阶段,我不明白如何正确地重新组织结构以使其能够像这样工作:

public sealed class ProductFactory
{
    public IProductHandler<T> GetHandler<T>(ProductType type) where T : ParentProduct =>
        type switch
        {
            ProductType.Parent => new ParentHandler()
        };
}

还值得考虑的是,必须在不使用显式类型转换as和比较typeof等方式的情况下完成要求。换句话说,这种格式不适合:

public interface IProductHandler
{
    public Task Add<T>(T product) where T : ParentProduct;
}

或者像这样

public interface IProductHandler
{
    public Task Add(ParentProduct product);
}

因为实现时需要明确转换类型。

更新: 在评论中他们询问我将如何使用它。项目中有多个这样的地方,主要是控制器动作和ViewComponent。控制器中使用的示例代码:

public sealed class ProductController(ProductFactory factory) : ControllerBase
{
    [HttpGet("{type}/{id:int}")]
    public async Task<IActionResult> DetDetails([FromRoute] ProductType type, [FromRoute] int id)
    {
        IProductHandler handler = factory.GetHandler(type)
        return Ok(await handler.GetDetails(id));
    }
}
c#
  • 1 个回答
  • 200 Views
Martin Hope
Maxim Wolf
Asked: 2025-02-07 16:21:01 +0000 UTC

时区的 TimeTZ 误解了时区

  • 4

有一个简单的 SQL 查询:

SELECT '06:00:00 +0600'::timetz at time zone '-05:00',
       '06:00:00 +0600'::timetz at time zone '+05:00'

我希望收到回复

+---------------+---------------+
|timezone       |timezone       |
+---------------+---------------+
|19:00:00 -05:00|05:00:00 +05:00|
+---------------+---------------+

但 PostgreSQL 产生相反的结果:

+---------------+---------------+
|timezone       |timezone       |
+---------------+---------------+
|05:00:00 +05:00|19:00:00 -05:00|
+---------------+---------------+

请告诉我这个问题的原因是什么。谢谢。

postgresql
  • 1 个回答
  • 16 Views
Martin Hope
Onebody
Asked: 2025-02-07 15:05:02 +0000 UTC

屏幕复制错误

  • 5

以前,屏幕复制可以正常工作,但在“显示设置”中的某个时候,开始出现错误“无法保存显示设置。尝试选择其他值”。我没有更改硬件/连接图/电线,所以错误可能出在系统/软件方面。

请告诉我可能存在什么问题?


硬件和软件:

  • 系统:Windows 10 64位
  • 屏幕一:小米电视。 HDMI-HDMI 连接。分辨率 3840x2160
  • 屏幕 2(主显示屏):BenQ LCD 显示器。 DisplayPort-DisplayPort 连接。分辨率 2560x1440
  • 显卡:Nvidia GeForce RTX 2070 super
  • 驱动程序:GeForce game Ready Driver 572.16

尝试过:

  • 通过 Windows+P 启用复制。它没有产生任何结果。
  • 将 GeForce 驱动程序回滚至版本 566.36 和 565.90。它没有产生任何结果。
  • 在两个显示器上设置相同的分辨率。它没有产生任何结果。
  • 连接 1 个额外的显示器而不是屏幕(LG,分辨率 1920x1080,HDMI-HDMI 连接)。复制对他有用。

在此处输入图片描述

windows-10
  • 1 个回答
  • 39 Views
Martin Hope
Dato Dato
Asked: 2025-02-07 12:34:00 +0000 UTC

如何从一个表中删除另一个表中所存在的行?

  • 5

有两个数据框:

  Reg_x    name BS_name Sector_name Reg_y   tac
0    IR  IR1400  IR1400  IR1400_053    IR  5286
1    IR  IR1397  IR1397  IR1397_053    IR  5286
  Reg    name BS_name Sector_name
0  IR  IR1400  IR1400  IR1400_053
1  IR  IR1400  IR1400  IR1400_052
2  IR  IR1400  IR1400  IR1400_051
3  IR  IR1397  IR1397  IR1397_053
4  IR  IR1397  IR1397  IR1397_052
5  IR  IR1397  IR1397  IR1397_051
3  IR  IR1307  IR1307  IR1307_053
4  IR  IR1307  IR1307  IR1307_052
5  IR  IR1307  IR1307  IR1307_051

我如何从第二个表中保存第一个表中不存在的名称?在这种情况下,您需要获得如下表格:

  Reg    name BS_name Sector_name
0  IR  IR1307  IR1307  IR1307_053
1  IR  IR1307  IR1307  IR1307_052
2  IR  IR1307  IR1307  IR1307_051

我认为可以通过列表来实现这一点,然后比较和过滤它们:

cesList = ces4gNokTable['name'].tolist()
    cesList = list(dict.fromkeys(cesList))
    print("Список (cesList) c незаполненными данными в CES 4G Nokia:")
    print(cesList)
    oldList = old4gTable['name'].tolist()
    oldList = list(dict.fromkeys(oldList))
    print("Список (oldList) c довесами 4G Nokia:")
    print(oldList)

但我认为通过熊猫有一些更好的解决方案

python
  • 2 个回答
  • 51 Views
Martin Hope
Евгений
Asked: 2025-02-07 07:09:22 +0000 UTC

Rsync文件过滤

  • 4

告诉我如何设置目录同步的例外?我只需要文件.dwg。

尝试过:

rsync --include '*.dwg' -av dir1 dir2/

rsync --exclude={'*.bak', '*.tmp'} -av dir1 dir2/

rsync --exclude-from={'~/dir/exclude-to-rsync.txt'} -av dir1 dir2

带有文件内容exclude-to-rcync.txt

*.bak
*.tmp
*.err
*.log
*.db
*.dwl2
*.original
*.txt
*.ion
*.xls
*.tif
*.shs
rsync
  • 1 个回答
  • 17 Views
上一页
下一页

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5