【问题标题】:What are the marker types for assemblies in .NET?.NET 中程序集的标记类型是什么?
【发布时间】:2020-04-19 11:26:46
【问题描述】:

.NET 中程序集的标记类型是什么?

我正在通过教程学习 AutoMapper,我在 here 上遇到了 marker types for assemblies 的概念:

// Or marker types for assemblies:
var configuration = new MapperConfiguration(cfg =>
    cfg.AddMaps(new [] {
        typeof(HomeController),
        typeof(Entity)
    });
);

在寻找我的问题的答案时,我遇到了this SO 问题。但我无法在那里找到答案。

【问题讨论】:

  • 从文档中,它们看起来就像恰好出现在感兴趣的程序集中的类型。 AutoMapper 只会调用Type.Assembly 来获取程序集。
  • 这没什么特别的,它只是意味着您向 Automapper 表明您对包含这些类型的程序集感兴趣。您正在为 Automapper “标记”它们。

标签: c# .net types automapper .net-assembly


【解决方案1】:

我猜,在AutoMapper 和你的样本范围内

// Or marker types for assemblies:
var configuration = new MapperConfiguration(cfg =>
    cfg.AddMaps(new [] {
        typeof(HomeController),
        typeof(Entity)
    });
);

它表示来自特定程序集的任何类型,用于“标记”程序集以扫描映射配置文件。将扫描包含 HomeControllerEntity 类型的程序集以获取从 Profile 继承的类型以进行映射器配置

AutoMapper 将扫描指定的程序集以查找继承的类 从配置文件并将它们添加到配置中

【讨论】:

    猜你喜欢
    • 2013-02-22
    • 2012-04-15
    • 1970-01-01
    • 2021-03-26
    • 1970-01-01
    • 2020-09-18
    • 2015-09-27
    • 1970-01-01
    相关资源
    最近更新 更多