$(ProjectDir)Libs\Afterthought\Afterthought.Amender.exe "$(TargetPath)" "$(TargetDir)EntityFramework.Patterns.dll"

我实际上分析代码好久,也没整明白它是怎么运行的,看一下官方文档明白了,原来。。。

Next, add the following as a post build step to your project to call the Afterthought Amender executable:

$(SolutionDir)packages\Afterthought.1.0.8\tools\Afterthought.Amender.exe "$(TargetPath)"

Please note that the \Afterthought.1.0.8\ portion of the path should reflect the version of Afterthought that you are using. You can also use the Amender build task in your project, but this requires manually editing the project to add this task. Since NuGet currently does not support modifying the project file directly in this way, Afterthought does not automatically configure itself to run for referenced projects.

If you instead chose to go the source route, simply configure your target project to call Afterthought.Amender.exe referencing the compiled output of the `Afterthought.Amender' project. Also, you can debug the amendment process by configuring the 'Afterthought.Amender' project to amend your target assembly and run this project in debug mode.

原来在事件后期执行这样的一个操作。

根据我们一直的习惯,直接在代码中解决问题的,但是这个工具是先编译通过,然后通过一个EXE程序来修改程序集,以达到效果。

然后修改的程序集你再用ILSpay看,会发现,

原始代码:

 
    [Auditable]
    public class AuditableEntity
    {
        public int Id { get; set; }
        public string Color { get; set; }
    }

Afterthought 以后,从ILSpay看到的代码,这一刻一切都明了了。。

using EntityFramework.Patterns.Extensions;
using System;
namespace EntityFramework.Patterns.Tests
{
    [Archivable]
    public class ArchivableEntity : IArchivable
    {
        string <DeletedBy>k__BackingField;
        DateTime? <Deleted>k__BackingField;
        public int Id
        {
            get;
            set;
        }
        public float Value
        {
            get;
            set;
        }
        public string DeletedBy
        {
            get
            {
                return this.<DeletedBy>k__BackingField;
            }
            set
            {
                this.<DeletedBy>k__BackingField = value;
            }
        }
        public DateTime? Deleted
        {
            get
            {
                return this.<Deleted>k__BackingField;
            }
            set
            {
                this.<Deleted>k__BackingField = value;
            }
        }
    }
}

然后,再看

[AttributeUsage(AttributeTargets.Assembly)]
  public class AmendAttribute : Attribute, IAmendmentAttribute
  {
      IEnumerable<ITypeAmendment> IAmendmentAttribute.GetAmendments(Type target)
      {
          if (target.GetCustomAttributes(typeof(AuditableAttribute), true).Length > 0)
          {
              ConstructorInfo constructorInfo = typeof (AuditableAmender<>).MakeGenericType(target).GetConstructor(Type.EmptyTypes);
              if (constructorInfo != null)
                  yield return (ITypeAmendment) constructorInfo.Invoke(new object[0]);
          }
          if (target.GetCustomAttributes(typeof(ArchivableAttribute), true).Length > 0)
          {
              ConstructorInfo constructorInfo = typeof(ArchivableAmender<>).MakeGenericType(target).GetConstructor(Type.EmptyTypes);
              if (constructorInfo != null)
                  yield return (ITypeAmendment)constructorInfo.Invoke(new object[0]);
          }
      }
  }

再看,

[assembly: Amend]

这家伙,通过在编译完成后,修改了程序,只要实现了IAmendmentAttribute , 那个exe 就知道了。随后一个字,更改dll文件啊,。。。,它就改了。 所以 也就是上个文件中 [pure] 也就有用了, maybe .net framework 了。

所以debug的时候,跟不到断点也是正常的了。因为你的程序已经对应的不是原来的代码了。

用一句歌词说: 我还是原来的我。 但程序集已经不是原来的程序集了。

当然,我说的断点是

  public class AmendAttribute : Attribute, IAmendmentAttribute

中的断点。

转载于:https://www.cnblogs.com/zbw911/archive/2013/02/06/2907651.html

Afterthought 原来是这样的啊。。。。相关推荐

  1. 入职体检体检错了_我们如何更新入职体验并获得更多用户

    入职体检体检错了 by William Woodhead 威廉伍德黑德(William Woodhead) 我们如何更新入职体验并获得更多用户 (How we updated our onboardi ...

  2. Paper:《Hidden Technical Debt in Machine Learning Systems—机器学习系统中隐藏的技术债》翻译与解读

    Paper:<Hidden Technical Debt in Machine Learning Systems-机器学习系统中隐藏的技术债>翻译与解读 导读:机器学习系统中,隐藏多少技术 ...

  3. qq空间网页设计_网页设计中负空间的有效利用

    qq空间网页设计 Written by Alan Smith 由艾伦·史密斯 ( Alan Smith)撰写 Negative space is a key design element that y ...

  4. cv::mat 颜色空间_网站设计基础:负空间

    cv::mat 颜色空间 Let's start off by answering this question: What is negative space? It is the "emp ...

  5. 印发 指南 通知_通知设计的综合指南

    印发 指南 通知 重点 (Top highlight) Peripheral messages in digital products, collectively known as notificat ...

  6. 胖子脸:库珀·布莱克100年

    In 16th century Europe, roman typefaces were the first to surpass blackletter as the preferred choic ...

  7. 成像数据更好的展示_为什么更多的数据并不总是更好

    成像数据更好的展示 Over the past few years, there has been a growing consensus that the more data one has, th ...

  8. 开源软件 安全风险_3开源安全风险及其解决方法

    开源软件 安全风险 Open source software is very popular and makes up a significant portion of business applic ...

  9. 如何开发一个hexo主题_如何确定一个强烈的主题可以使产品开发更有效

    如何开发一个hexo主题 by Cameron Jenkinson 卡梅伦·詹金森(Cameron Jenkinson) 如何确定一个强烈的主题可以使产品开发更有效 (How identifying ...

最新文章

  1. ZOJ 1025 Wooden Sticks(快排+贪心)
  2. 【干货】前端自学之路(持续更新)
  3. lightingJS
  4. 【MPI编程】任意数节点的树形求和(高性能计算)
  5. kafka配置文件server.properties
  6. codeforces 906C
  7. [模板] 线筛欧拉函数
  8. Linux系统管理.Samba配置文件
  9. Xshell使用教程(不断总结...)
  10. 炫酷 雨滴桌面设置工具
  11. Layui Select四级联动效果触发
  12. java概述及我的第一个java项目
  13. Python语言程序设计基础_期末作品设计——收银软件(2020-2 B)_答案_通识教育必修课程_上海师范大学
  14. 如何封禁大量恶意IP?
  15. 【第五篇】Maven系列教程-聚合工程
  16. SQL like子查询
  17. 抖音快手如何快速涨粉技巧整理
  18. 计算机哪个按键可以和弦,钢琴键盘和弦图解大全!作曲必看!老师和家长快收藏起来...
  19. hadoop 四种压缩格式
  20. BMZCTF WEB WEB_penetration

热门文章

  1. CF思维联系–CodeForces -224C - Bracket Sequence
  2. 【IT笔试面试题整理】链表
  3. bart使用方法_使用简单变压器的BART释义
  4. 一般线性模型和混合线性模型_线性混合模型如何工作
  5. 乱用信用卡?黑名单见
  6. 数据库设计笔记——概述(一)
  7. “穿透”与“征兆”:长篇小说《环形女人》(一)
  8. 异构服务器 微服务_Spring Cloud Alibaba Sidecar 多语言微服务异构
  9. 高性能计算机 和服务器,一种高性能计算机服务器
  10. android 文件公有存储,如何将文件写入Android中的外部公共存储,以便从Windows中看到它们?...