文章出處

//目的,想自己生成實體類,不走dc的生成機制,所以研究一下此方法。
public
void GenerateEntities(string generatedAssemblyFile) { lock (this.lockObjectForDC) {
     //此數組為要生成代碼的接口類型 Type[] entityInterfaces
= this.entitiesToGenerateInfo.GetEntityInterfaces(); if (!this.IsAlreadyBuild && (entityInterfaces.Length > 0)) {
        //生成過了,且有實體接口,有文件的情況下,直接加載
if (File.Exists(generatedAssemblyFile)) { this.generatedAssembly = Assembly.LoadFrom(generatedAssemblyFile); } else {
          //沒有文件,馬上生成一個。 DCBuilder builder
= new DCBuilder(this.typesInfo); builder.Setup(this.entitiesToGenerateInfo, this.customLogics, this.existingImplementorsInfo); this.generatedAssembly = builder.GetAssembly(generatedAssemblyFile); } this.ProcessGeneratedAssembly(this.generatedAssembly);
          //遍歷所有的實體類,即接口定義 Dictionary
<Type, object> dictionary = new Dictionary<Type, object>(); foreach (Type type in entityInterfaces) {
        //沒處理過的
if (!dictionary.ContainsKey(type)) { dictionary.Add(type, null);
              //標記為處理過。
              //處理“基”接口
foreach (Type type2 in type.GetInterfaces()) {
              //已經注冊過的實體類中包含這個接,且,沒處理過此接口時,把基接口也加進來
if (this.registeredEntityTypes.Contains(type2) && !dictionary.ContainsKey(type2)) { dictionary.Add(type2, null); } } } }
foreach (Type type3 in dictionary.Keys) {
          //上面收集到了所有需要用到的接口,刷新類型信息。使用實際類型查找接口
this.typesInfo.RefreshInfo(type3); Type entityTypeByInterface = this.GetEntityTypeByInterface(type3); if (entityTypeByInterface != null) { this.typesInfo.RefreshInfo(entityTypeByInterface); foreach (TypeInfo info in this.typesInfo.FindTypeInfo(entityTypeByInterface).RequiredTypes) { info.Refresh(true); } } Type dataTypeByInterface = this.GetDataTypeByInterface(type3); if (dataTypeByInterface != null) { this.typesInfo.RefreshInfo(dataTypeByInterface); } }
    
foreach (Type type6 in this.generatedAssembly.GetExportedTypes()) { if (this.TypeIsKnown(type6)) { TypeInfo info2 = this.typesInfo.FindTypeInfo(type6); if ((info2 != null) && (info2.Source != this)) { info2.Source = this; this.typesInfo.RefreshInfo(type6);
              //類typeinfo附source的值,即TypeInfoSource } } } } } }

 


文章列表


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()